Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JFreeChart Combined XY Plot with Time Series

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)?

like image 707
alrts Avatar asked Jan 24 '12 22:01

alrts


1 Answers

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);
like image 75
alrts Avatar answered Sep 22 '22 15:09

alrts