1

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!

Daniel
  • 13
  • 1
  • 3
  • If this is a duplicate account, you can request a [merge](http://meta.stackexchange.com/questions/18232/how-can-one-link-merge-combine-associate-two-accounts-users-anonymous-unregiste/73801#73801) of your other account. – trashgod Sep 12 '11 at 18:15

2 Answers2

1

Have a look at Range class .

There are many methods like

combine(Range range1, Range range2)
          Creates a new range by combining two existing ranges.

expandToInclude(Range range, double value)
      Returns a range that includes all the values in the specified range AND the specified value.

shift(Range base, double delta, boolean allowZeroCrossing)
          Shifts the range by the specified amount.

You can use any depending upon your requirements

you might even have to add following [based on your comments]

timeaxis.setAutoRange(true);
timeaxis.setFixedAutoRange(1000.0);
Manish Singh
  • 3,463
  • 22
  • 21
  • thanks for the response. when I create the plot, i used a Range to set the axis. e.g. yRange = new Range() and pass it to the axis. later when the chart is updated on the new data, I changed yRange but the chart still has the old range after repaint. or do I need to retrieve it from the chart object directly? – Daniel Sep 07 '11 at 03:42
1

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045