JFreeChart Combined XY Plot with Time Series
Asked Answered
V

1

6

I want to place two Time Series Charts sharing the same time domain axis above each other, both with multiple datasets.

chart1 = ChartFactory.createTimeSeriesChart("", "", "", tsc1, true, true, false);
subplot1 = chartCOT.getXYPlot();
...
chart2 = ChartFactory.createTimeSeriesChart("", "", "", tsc2, true, true, false);
subplot2 = chartCOT.getXYPlot();
...

where tsc1 and tsc2 are TimeSeriesCollection datasets containing multiple TimeSeries which both have the same date range of about 5 years.

When I plot them individually, there is no problem, i.e. the time domain axis reflects the calendar dates as desired.

As soon as I combine the two plots by means of the construction:

CombinedDomainXYPlot plot = new CombinedDomainXYPlot();
plot.setGap(10.0);
plot.add(subplot1, 2);
plot.add(subplot2, 1);
chart[ch] = new JFreeChart("label", null, plot, true);

the charts appear above each other, as desired, but the time axis does not show calendar dates anymore but values like 0, 250'000'000'000, 500'000'000'000 and so on, as they were presenting milliseconds. Furthermore, the time range is extended to the left side for about 30 years and the plot data (beginning with the year 2006) starts in the far right side and accordingly is very much compressed.

How can I preserve the correct representation of the domain axis (calendar dates between 2006 and 2012)?

Vengeful answered 24/1, 2012 at 22:10 Comment(1)
Please edit your question to correct the identifiers and to provide an sscce that exhibits the problem you describe.Newish
V
9

I have finally found the solution to the problem by myself:

When I initialize the CombinedDomainXYPlot, it allocates a numberAxis as default, and does not use the axis already defined by the subplots.

Therefore I had to tell plot that the domain axis is a time series:

ValueAxis domainAxis = new DateAxis("");
plot.setDomainAxis(domainAxis);
Vengeful answered 29/1, 2012 at 11:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.