I have a JFreeChart time series chart, which displays a TimePeriodValuesCollection. The dataset contains two intervals. The data is appearing correctly and I am able to pan (with Ctrl-drag) the view. The problem is that if I zoom in, and I pan the view to the right in the zoomed view, the second interval suddenly disappears after the first interval is no longer visible.
Everything is OK, if there is only one interval, or if I don't zoom in.
Any thoughts?
SSCCE:
public class DisappearingTest {
public static final SimpleDateFormat oracleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
buildFrame();
}
});
}
private static void buildFrame() {
JFrame f = new JFrame("Test");
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JPanel chartPanel = null;
try {
chartPanel = createChartPanel();
} catch (ParseException e) {
e.printStackTrace();
}
f.add(chartPanel);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
static JPanel createChartPanel() throws ParseException {
TimePeriodValues timePeriodValues = new TimePeriodValues("Test");
Date startDate1 = oracleDateFormat.parse("2011-01-01");
Date endDate1 = oracleDateFormat.parse("2011-12-31");
timePeriodValues.add(new Second(startDate1), 0.3);
timePeriodValues.add(new Second(endDate1), 0.3);
Date startDate2 = oracleDateFormat.parse("2012-01-01");
Date endDate2 = oracleDateFormat.parse("2015-12-31");
timePeriodValues.add(new Second(startDate2), 0.5);
timePeriodValues.add(new Second(endDate2), 0.5);
TimePeriodValuesCollection dataSet = new TimePeriodValuesCollection();
dataSet.addSeries(timePeriodValues);
JFreeChart chart = ChartFactory.createTimeSeriesChart("Title", "Time", "Value", dataSet, true, true, false);
XYPlot plot = chart.getXYPlot();
plot.setDomainPannable(true);
plot.setRangePannable(true);
ChartPanel chartPanel = new ChartPanel(chart);
return chartPanel;
}
}