Android: Shifting array one position to make a dynamic graph
<p><strong>UPDATE:</strong></p>

<p>Runs like a charm now. With the help of Alex Klimashevsky who pointed me in the right direction. Basically I meshed up the for loop. This is what it should be:</p>

<pre><code>for(int a = 1; a &lt; x.length; a++) {
    y[(a)]=yprev[a-1];
}
y[0]=value_i/10;

for(int a = 0; a &lt; x.length; a++) {
    yprev[a]=y[a];
}
</code></pre>

<p>Thanks!</p>

<p>Maybe someone can tell me what is going wrong:
It is a really basic plotting program, but it is good enough for now.</p>

<p><strong>I declared this on the top of my view class:</strong></p>

<pre><code>private int[] x = {50, 60, 70, 80, 90, 100, 110,120,130};
private int[] y= {500,500,500,500,500,500,500,500,500};
private int[] yprev={500,500,500,500,100,500,500,500,500};
</code></pre>

<p><strong>And I put this within onDraw:</strong></p>

<pre><code>for(int a =  (x.length-1); a ==0; a--) {
    y[(a+1)]=yprev[i]; //Shift everything one place to the right
}
y[0]=value/10; //Fill in the newest value for temperature on the first index

for(int a =  (x.length); a ==0; a--) {
    yprev[a]=y[a]; //Store the latest array, such it can be re-used in the next cycle**
}

paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(2);
paint.setColor(Color.RED);

Path path = new Path();
path.moveTo(x[0], y[0]);
for(int b = 1; b &lt; x.length; b++) {
    path.lineTo(x[b], y[b]);
}
canvas.drawPath(path, paint);
</code></pre>

<p>Plotting works, but somehow it doesn't shift my plot. The new value is every time plotted on the first index and all other values remain 500.
Any ideas?</p>

<p>Best regards,
Kevin</p>
