How to make a real time scrolling plot?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
taojiang_2000
Posts: 6
Joined: Mon Jan 26, 2009 2:12 pm
Location: USA
Contact:

How to make a real time scrolling plot?

Post by taojiang_2000 » Sun Feb 22, 2009 6:37 pm

This is a related to my previous post "How to make JFreeChart support real-time charting?". Real time XY plot is the fundamental plot for every real time related plots. Scrolling real time plot can be implemented as a fixed auto range plot with adjustable range.

I have modified jfreechart-1.0.12 by adding real time plotting capability and created examples for both realtime xy plot and scrolling plot under the org.jfree.chart.demo. The package is uploaded at:
http://tjiang2000.googlepages.com/jfree ... 0.12rt.zip

You can use windiff to find what I have done on jfreechart-1.0.12 package. This package also fixed some rendering bugs in previous posting. The testing focuses are:
1. speed: two demos are running at 50hz.
2. resizing chart panel continuously to see if there is any CPU or memory usage spike.
3. or, whatever you can think about.

The demos are bare minimal. Since Jfreechart is very powerful, you can add some decorated pieces, such as: grid, background image, etc fancy stuff to see there isn't any noticeable performance deterioration.

develop
Posts: 296
Joined: Wed Mar 23, 2005 10:01 pm

Re: How to make a real time scrolling plot?

Post by develop » Tue Mar 24, 2009 3:31 pm

is there any way we can accommodate all these changes in Jfreechart itself ?
can you be a little specific what is changed ??

Thanks

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: How to make a real time scrolling plot?

Post by david.gilbert » Wed Mar 25, 2009 5:40 pm

I think it would be good to make a web start demo of this available, so that people can evaluate your changes more easily. However, I did go to the trouble of compiling the sources and running your demos...they seem to rely on having the axis ranges NOT change in order to avoid having to redraw some things, and it doesn't play nicely with the ChartPanel zooming options. I also wonder if you'd see some problems with overlapping in cases where you have more than one series in a chart. I appreciate the effort you've gone to, but you haven't convinced me yet.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

taojiang_2000
Posts: 6
Joined: Mon Jan 26, 2009 2:12 pm
Location: USA
Contact:

Re: How to make a real time scrolling plot?

Post by taojiang_2000 » Tue Mar 31, 2009 3:55 am

I have made two web start demos:
1. real time plot at: http://tjiang2000.googlepages.com/rt_demo.jnlp
2. real time scroll plot at: http://tjiang2000.googlepages.com/rt_scroll_demo.jnlp

Yes, I did purposely fix the range of xaxis and borrow the setLowerMargin and UpperMargin parameter to set how up how much I need to scroll. For example, if the value is set to 0.25, it means when plot reaches the right end boundary, it will scroll 1/4 of the plot to left and leave 1/4 of whole plot area to plot the new stuff.

I think for very hight speed real time plot, the zooming options should be disabled for two reasons:
1. simplicity: the performance gain of my approach is achieved by only draw two points at a time. Once zoomed, I need to notify the dataset to draw the full set. However, zooming is implemented inside ChartPanel and it is very hard from ChartPanel to get information on dataset unless adding lots of code.
2. realistic: for very high speed plot, it will be very difficult for user to watch the zoomed area because the plot will move much faster than the regular plot. unless they want stop the plot and then zoom. The other alternative option is to take a snapshot and store it in SVG format and let browser to do zooming.

Yes, I did see overlapping when more then one series in a chart. This is because I plot them in random values. One way to fix it is to create a CombinedDomainXYPlot to hold multiple XYPlots and let each XYPlot hold one series but let them share the same xaxis. Or another simple way is to add some offset value for each of series and let them separated.

Thanks.

anirudhak
Posts: 15
Joined: Thu Apr 30, 2009 11:06 am

Re: How to make a real time scrolling plot?

Post by anirudhak » Wed Jun 24, 2009 6:15 am

hi ,
its very useful for me . but can u tell what changes u made to jfreechart api , because i want to implement this is chartcomposite so i want to modify it according to this requirements .

Thanks,
anirudh.k

maswjxh
Posts: 5
Joined: Thu Jul 30, 2009 7:06 am
antibot: No, of course not.

Re: How to make a real time scrolling plot?

Post by maswjxh » Sun Aug 02, 2009 8:29 am

i have download the "jfreechart-1.0.12rt.zip" and compile it, then i run the demo example,but i found a little question,when i clicked the mouse,the chartpanel refresh and only redraw the new point. the older point not redraw. what happened? But I run the "rt_scroll_demo.jnlp" example, i haven't found this problem.

taojiang_2000
Posts: 6
Joined: Mon Jan 26, 2009 2:12 pm
Location: USA
Contact:

Re: How to make a real time scrolling plot?

Post by taojiang_2000 » Sun Aug 02, 2009 3:52 pm

The key to make chart draw fast is to only draw two points at a time unless the total refreshing chart. Take a look at refresh() function of RealTimeXYScrollSeriesDemo.java. refresh() function continously checks whether data is still in the range of xaxis. If so, just return; otherwise, it attaches to new range and calls dataset.restore() to do a full plots for all points.

After pressing Stop button, the timer no longer fires event to pump any new data and refresh() will no longer being called. When click a mouse on the chart panel, the system will repaint the panel but without calling refresh() function first. Therefore, only the last two points will be called.

If you understand the mechanism, you can change the behavior the demo program to whatever you need.

Hope this is helpful.

Tao

maswjxh
Posts: 5
Joined: Thu Jul 30, 2009 7:06 am
antibot: No, of course not.

Re: How to make a real time scrolling plot?

Post by maswjxh » Mon Aug 03, 2009 2:36 am

Thank you! but when I run the "http://tjiang2000.googlepages.com/rt_scroll_demo.jnlp", i clicled the mouse, and the example plot all points!
In fact,i have found why this problem happened in my code(all copy from your code) ,but i don't understand why there are different behavior between them.
another question,can we dispaly the crosshair or tooltip to show the values?
your code i have study,the mechanism i can understand,and this code is useful for me and i have write an application i want to do !Thank you!Thank you for reply!

maswjxh
Posts: 5
Joined: Thu Jul 30, 2009 7:06 am
antibot: No, of course not.

Re: How to make a real time scrolling plot?

Post by maswjxh » Thu Aug 06, 2009 8:06 am

Thank you! I have done some other work i want!

NANA SASA
Posts: 1
Joined: Wed Jun 08, 2011 4:25 pm
antibot: No, of course not.

Re: How to make a real time scrolling plot?

Post by NANA SASA » Wed Jun 08, 2011 4:52 pm

plz i wanna a code source java that help me to draw a pie chart for exemple by using data from my database i wish that graph refrech every x second plz can u help me . my e-mail is : flower.white21@gmail.com

Merci

gavinpalmer1984
Posts: 2
Joined: Mon Sep 26, 2011 9:58 pm
antibot: No, of course not.

Re: How to make a real time scrolling plot?

Post by gavinpalmer1984 » Mon Sep 26, 2011 10:07 pm

Thank you Tao.

I successfully used Tao's real-time chart.

Performance is incredible. I have a timer firing every 20 msecs with over 10000 entries. the refresh function has to handle yaxis and multiple series.

gavinpalmer1984
Posts: 2
Joined: Mon Sep 26, 2011 9:58 pm
antibot: No, of course not.

Re: How to make a real time scrolling plot?

Post by gavinpalmer1984 » Wed Sep 28, 2011 5:20 am

I have zooming. I created an interface in ChartPanel.java that I override from my implementing class. The interface lets me repaint and refresh as needed. For those who try to use zoom - I did run into a naming conflict in the overriden function with the "refresh" function in ChartPanel.java and myClass.java.

But everything is working well for me. I can zoom in and out with the left-click-drag zoom rectangle. My real-time data continues to populate even though I can't see it when I am zoomed in. When I zoom out - the data is there.

chartPanel = new ChartPanel(chart, true){
@Override
public void zoomIn () {
dataset.restore();
chartPanel.repaint();
}
@Override
public void zoomOut () {
myClassRefresh();
chartPanel.repaint();
}
};

chrisrhyno2003
Posts: 30
Joined: Thu Jun 18, 2015 5:42 pm
antibot: No, of course not.

Re: How to make a real time scrolling plot?

Post by chrisrhyno2003 » Thu Jun 18, 2015 5:45 pm

Hi,

I tried downloading the jnlp files. It gives me an error. Can someone tell me how can I include Tao's files? I was able to download them .I don't know how to proceed further? Do I make a jar and all it to my project?

Can someone send me example code of a chart with real time scrolling plot ? my email is ash_venkat@rediff.com

Thanks,

Locked