Plotting a line graph using canvas

Hi there everyone!

I am currently learning how to use MIT app and have met with a problem

I want to plot a line graph with all the sensor data I have sent to a server through the access point and display it in my app, displaying the individual data was fine however I can't seem to plot the graph out.

So what I did was increased the "X" value for each loop so I could plot over the entire graph. Once the "Y" data is saved then can create a line between previous and present data using the DrawLine block. In that block, the height bust is the total height of the graph minus the received data. I also check if X have reached the maximum width of the graph. If yes, reset the Canvas and start plotting once again from the beginning of the graph and also reset the "X" values to 0.

But it does not seem to work, attached is the code

Can anyone help and see if i have done any of it wrongly?

Thank you in advance!
mitapp

Welcome

Here is a Forum discussion where one developer developed a ‘seismograph’ using AI2 and the Accelerometer and a Canvas. He plots smooth x,y and z curves simultaneously. The example might be something you could do to plot your data… see Seismic …Look at the aia on the 6/25/14 post.

This example of course is not using a server to source the data stream; you would have to adapt the code. The example does plot a nice real time graph using the Canvas.

You are updating global variables X_before and Y_before too soon, before you had a chance to use them in your Canvas1.DrawLine block.

Move those two set global variable blocks to immediately after the DrawLine block.

3 Likes

I have take a look at it ! Thank you for the suggestion/help!

thank you for the help!