• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
thanaphum bannasri
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think calling the JFreeChart object's fireChartChanged method should do the trick.
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic