Search code examples
javagraphvisualizationjfreechartgraphing

JFreeChart initial 'zoom'


I am using JFreeChart 1.0.19 to create a timeseries graph. The graph contains both positive and negative values, however when the graph is initially displayed the Y axis always baselines to 0, and therefore I only know about the negative numbers when I manually zoom out.

Is there a way to get JFreeChart to display the full range when it is first drawn.

I have tried:

Number maximum = DatasetUtilities.findMaximumRangeValue(data);
Number minimum = DatasetUtilities.findMinimumRangeValue(data);        
((XYPlot)timeSeriesChart.getPlot()).getRangeAxis().setRange(minimum.intValue(),
maximum.intValue());
  • Setting the range to a static negative min value.
  • Googling it

The API doc doesn't seem very clear on why this behaviour is or how to alter it. Any help appreicated.


Solution

  • @raul1ro was along the right lines. I solved this by adding:

    timeSeriesChart.getXYPlot().getRangeAxis().setDefaultAutoRange(new Range(minimum.doubleValue(), maximum.doubleValue()));