• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think calling the JFreeChart object's fireChartChanged method should do the trick.
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic