wangyao5 / achartengine

Automatically exported from code.google.com/p/achartengine
0 stars 0 forks source link

How to update chart dynamically? #121

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi to all and thanks in advance :)

I'm quite new to achartengine so I have a question.
I know that I can create new GraphicalView with specified set of XY points and 
show it on the screen:

GraphicalView view = ChartFactory.getLineChartView(mContext, mXYDataSet, 
mXYMultipleRenderer);

But when the view has already created, there is no method that performs 
adding/removing points on chart inside GraphicalView class.

In my project I need to update chart dynamically with new dataset every second. 
I there any solution which excludes changing achartengine's sources?

Thank you,
Alex

Original issue reported on code.google.com by alkon...@gmail.com on 18 Aug 2011 at 2:54

GoogleCodeExporter commented 9 years ago
I modified achartengine to be able to dynamically add points. It is very 
unmanageable, since it is basically a fork of the library from a year ago.

So, no, there's no way to do what you ask without modifying achartengine.

To the dev: this would be an awesome feature, but obviously requires a 
re-engineering part of the way the engine works.

Original comment by jondwil...@gmail.com on 19 Aug 2011 at 5:40

GoogleCodeExporter commented 9 years ago
Add new data to the dataset and call view.repaint();

Original comment by dandrome...@gmail.com on 23 Aug 2011 at 12:21

GoogleCodeExporter commented 9 years ago
The only problem with calling view.repaint() is that it calls the view's 
invalidate() function and forces a redraw of the entire view, not just the 
internal graphing element. This is VERY costly in terms of memory overhead and 
causes the garbage collector to go crazy. Each time the garbage collector runs, 
it may take up to several hundred milliseconds. Thus, AChartEngine in its 
current state can not be effectively used for realtime graphing.

To the dev: is there a way to add a method that will only redraw the 
graphing/charting element to reduce memory cost and avoid garbage collection?

Original comment by pr...@control-tec.com on 1 Jul 2013 at 7:58

GoogleCodeExporter commented 9 years ago
There is another version of the repaint method that allows you to only 
invalidate a certain part of the screen: repaint(int left, int top, int right, 
int bottom);

Original comment by 4viewsoft@gmail.com on 19 Jul 2013 at 2:30

GoogleCodeExporter commented 9 years ago
Can somebody give any little example of usage repaint(int left, int top, int 
right, int bottom); ?
Can't get it working.
I'm trying to draw real-time graph (ECG), and it goes slow after a few hundred 
of points with repaint(). 
Now, after loading new part of ecg-data from sensor I calculate minimum and 
maximum X-value of new points. Then I convert (minX, maxX) in GraphicalView 
coordinates (left, right) using appropriate scale factor. Then I call 
repaint(max(0,left-5), 0, min(width,right+5), height); and it is not working.
After inspecting source code of GraphicalView and XYChart I conclude that this 
is because repaint(left, top, right, bottom) method simply draws ENTIRE dataset 
in appropriate region of GraphicalView instead of drawing only A PART of 
dataset which is within region. Then I tried to change renderer's XAxisMax and 
XAxisMin before calling repaint(left, top, right, bottom) with calculated 
bounds of new data points, and again have no success...

Original comment by konel...@gmail.com on 9 Mar 2014 at 9:30