I am seeing the same kind of problem with 'autorange' and a timeseries. In this case, the autorange does not see a value if it is for a Day added into an existing series, after a 'within-range' point has been added for the same Day.
I haven't seen a workaround in related questions. Once the range-extending point has been missed, it does not get recognized by further 'fireSeriesChange' or zoom-in/restore zoom operations.
A sample program showing the problem. The chart should display, then add another point after 3 seconds which will be off of the top of the plotted data area:
Code: Select all
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
/**
* Demonstrate the problem showing up trying to use autorange.
*/
public class DemoAutoRangeProblem extends JPanel {
private final JFreeChart mChart;
public DemoAutoRangeProblem() {
mChart = buildChart();
add(new ChartPanel(mChart));
addData();
}
/** Build a chart with for values in a timeseries */
private JFreeChart buildChart() {
DateAxis xaxis = new DateAxis("Date");
NumberAxis yaxis = new NumberAxis("Count");
yaxis.setAutoRange(true);
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);
TimeSeriesCollection dataset = new TimeSeriesCollection();
XYPlot plot = new XYPlot(dataset, xaxis, yaxis, renderer);
JFreeChart chart = new JFreeChart("Demo Autorange Problem", plot);
return chart;
}
/** Create some initial data */
private void addData() {
TimeSeries series = new TimeSeries("Count");
series.add(new Day(20, 8, 2012), 5);
series.add(new Day(21, 8, 2012), 2);
series.add(new Day(22, 8, 2012), 10);
((TimeSeriesCollection) mChart.getXYPlot().getDataset()).addSeries(series);
}
/** Add more data points, going above the existing range */
public void addMoreData() {
TimeSeriesCollection dataset0 = (TimeSeriesCollection) mChart.getXYPlot().getDataset(0);
TimeSeries series = dataset0.getSeries(0);
//
// if add a point within the current range,
// and then adding a value at same day but above the range,
// the 'auto-range' does not see the higher value.
//
series.addOrUpdate(new Day(23, 8, 2012), 8);
series.addOrUpdate(new Day(23, 8, 2012), 19);
}
/** Show the demo chart */
public static void main(String[] args) {
DemoAutoRangeProblem gui = new DemoAutoRangeProblem();
JFrame f = new JFrame("Demo of autorange problem");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(gui);
f.pack();
f.setVisible(true);
// waiting until chart is displayed, then adding more data points
try {Thread.sleep(3000);} catch (InterruptedException e) {;}
gui.addMoreData();
}
}
thanks,
Steve