Java – dynamically change Y axis range in Jfreechart

javajfreechart

I have a time series data which I can draw using jfreechart. the issue is, as new data comes in, the chart will change based on the new dataset. I used,

chart.fireChartChanged();
chartPanel.repaint();

the issue is, some data may be out of the current range of Y axis, I'm wondering how can the axis range be changed according to the maximum value in the timeseries I had so far? thanks!

Best Answer

I used chart.fireChartChanged(); chartPanel.repaint();… but the chart still has the old range after repaint.

This all seems unnecessarily complicated: axis ranging and notification should be automatic. In this example, the range changes as outliers accumulate, because add() "sends a SeriesChangeEvent to all registered listeners." In this example, the range is fixed, but the same notification happens.

As we can't guess how your program fails in this regard, it may help to provide an sscce that exhibits the problem(s) you describe.

Related Topic