File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes how do i get plot x Axis every 5 minute (JFreechart) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how do i get plot x Axis every 5 minute (JFreechart)" Watch "how do i get plot x Axis every 5 minute (JFreechart)" New topic

how do i get plot x Axis every 5 minute (JFreechart)

thanaphum bannasri

Joined: Jan 24, 2011
Posts: 5

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
I think calling the JFreeChart object's fireChartChanged method should do the trick.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

I suspect you don't actually want a new plot every 5 minutes. It is more normal to have a running plot where the X axis always displays the values from the last 5 minutes with the axis being update every second or so. To achieve this one needs to create an initially empty model that only store the values from the last 5 minutes and then, using a Swing timer, update the model every second or so by adding new values and and removing values more than 5 minutes old.

Using JFreeChart this is achieved by using a TimeSeries as the model and using the method setMaximumItemAge() to define how long the collection period is. In your case 5 minutes. Each time you add a new point to the TimeSeries using the timeseries.addOrUpdate() method points more than 5 minutes old will automatically be discarded. When you add a new point to the model you will need to set the display period to the last 5 minutes. This is simple if you use DateAxis for the X axis by using something along the lines of

Using this I tend to update the date axis more frequently than I update the model (typically 10 times a second) since then the axis flows rather than jerks across the screen but since your collection period is so large I doubt if this matters.

There is no need to explicitly fire any events. All updates of the model and X axis fire appropriate events. Sometimes I find this annoying because I often want to delay firing events until I have made a set of changes but what the heck - it is very very good and free.

Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
I agree. Here's the link:
subject: how do i get plot x Axis every 5 minute (JFreechart)
It's not a secret anymore!