JFreeChart DynamicTimeSeriesCollection with a period of n milliseconds

I am trying to define an applet with a chart that should be updated every n milliseconds. For example, every 500 milliseconds. This is part of the code:

dataSet = new DynamicTimeSeriesCollection(1, 200, new Millisecond());
dataSet.setTimeBase(new Millisecond());

When I run the application, it returns me a NullPointerException raised by the second line. If I replaced Milliseconds with Seconds, it will work.

The question arises: how to set the period to milliseconds without exceptions?

thank

+3
source share
1 answer

It pointsInTimedoesn't seem to be initialized to Millisecond, but you can do it in the constructor of the subclass:

private static class MilliDTSC extends DynamicTimeSeriesCollection {

    public MilliDTSC(int nSeries, int nMoments, RegularTimePeriod timeSample) {
        super(nSeries, nMoments, timeSample);
        if (timeSample instanceof Millisecond) {
            this.pointsInTime = new Millisecond[nMoments];
        }
    }
}
+4
source

Source: https://habr.com/ru/post/1794922/


All Articles