1

I am new to JFreeChart.

I'd like to change the code of Trashgod to monitor something in Java. So I need to:

1 - Keep all datas shown. His code keeps only the last 10 samples.

2 - Having a variable scale on X-axis :

  • Having an int input howManyDays (or something like an int input, something a little bit clever would be great ;-) ) : int howManyDays = 7;//in this case : 1 week of datas

  • Having a variable scale on X-axis a little bit complex : For example during the first seconds of execution it has for scale 1 minute. Then 10 minutes... When midnight has been passed, it should print the current day.

I know that this instruction

      Timer timer = new Timer(100, new ActionListener()

means that every 100 ms it adds a new data and then it updates the chart. I'll change it to 10 000 -> 10 seconds. My Timer for testing JFreeChart :

            Timer timer = new Timer(10000, new ActionListener() {
                private int i,data;
                @Override
                public void actionPerformed(ActionEvent e) {
                    if ((i%10)==0) {
                        this.data += (int) Math.ceil(2*Math.random());
                    }
                    this.i++;
                    chart.update(this.data);
                }
            });

Of course I don't need the solution.

What do I really need :

  • Maybe if someone could add comment on Trashgod's code ?
  • Or if someone could give me some tricks for doing this kind of code ?
  • Or maybe someone has already done something like that ?

Have a good day !

Community
  • 1
  • 1

1 Answers1

1

While your question is somewhat broad, here are some pointers to approaching such a task.

  • DynamicTimeSeriesCollection is designed to retain only recent data, not all; note here how the time slots are filled.

  • To keep all data, use a TimeSeries as suggested here; aged items will be removed only if you invoke setMaximumItemAge().

  • To format the time axis, use setDateFormatOverride() as suggested here; the tick units will adjust automatically as data accumulates; don't change them unless you have some some specific reason to do so.

  • To collect data in the background, use a SwingWorker, as shown here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Thanks ! I'll try what you suggest – Benjamin Bettan Feb 29 '16 at 12:39
  • Well... I use a DB for my data... So I'll use a plugin of Eclipse : Birt – Benjamin Bettan Mar 01 '16 at 21:06
  • For having real-time on Eclipse click on Script then clientScripts. Then paste this script : [link](https://www.eclipse.org/forums/index.php/t/163879/) then run in external browser – Benjamin Bettan Mar 01 '16 at 21:14
  • First steps on birt : https://www.youtube.com/watch?v=23AZ7Hivzyg https://www.youtube.com/watch?v=_kpH3LYhmk4 – Benjamin Bettan Mar 01 '16 at 21:31
  • It's for beginers on birt (in this video the result at the end is a table but you can do charts as well with Birt) : you'll need to download your jdbc driver then update your datasource. then you can create your querry and finally update your layout – Benjamin Bettan Mar 01 '16 at 21:44