2-D dynamic plotting
This class can be used to plot dynamically changing data such as Sensor data on Android. It can be used as part of a more complex View and it automatically takes care of the screen parameters.
Constructor:Â plotDynamic(Context context)
Public method addData(float) can be used to add the next data point to be plotted. invalidate() forces the replotting of the canvas. Method clearData() clears up the canvas. When the number of points to be plotted exceeds the available screen space the initial values are removed. This results in a plot which appears to move to the left with the new values being added to the right.
Thanks for posting the code. Can you elaborate on how to use this class? I have declared an instance of it in my main activity but can't show it on the layout. Any pointers will be appreciated.
I would also like to thank you for posting your code. I am able to get the layout as desired but I am having trouble adding a data point. Programming is not necessarily my strong point, so I as well would really appreciate an elaboration on the usage of this code. Thanks Again!
Hi Colt, It has been some time since I used this code but I feel it should work without much ado. As I mention, addData( float) can be used to add an additional data point to the vector of data points which are being plotted and then a subsequent call to invalidate() would replot the new vector.
Can you please send full code to my email
Can you plot the points dynamically in the opposite X-axis direction? Let's say I receive the point (6169,14) and then (5056, 12) and after that (4000,15), will it crash?
I have tried with AchartEngine using XYseries graph and it crashes since when it receives the points in wrong order, since the points are not sorted it crashes.
Providing a small guide on how to plot and showing the results with images would be nice.
Thx!
It was a long time ago but from what I can tell it should work. Basically the dynamic effect is created by plotting frame by frame. For each frame, a vector containing x and y values is taken and each pair is joined to the next one. From a cursory glance I don't see why it would not work but I might be wrong in my assessment.
Thanks, your code provide me a very good base for my own plot.
can you please send complete source code for this?
I am new to android.
Thanks in advance
Hi Anjan, I made this a long time ago and this is all the code that I have for this now. It has worked well enough for several others, however.