Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

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: 43016
76
  • 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.
 
I love a good mentalist. And so does this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic