JFreeChart 时间序列组合 XY 图表

6

我希望在同一个时间轴上放置两个时间序列图,它们位于彼此之上,都包含多个数据集。

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

tsc.addSeries(tsc2.getSeries(0));

the time domain axis gets corrupted and shows only a relative range of about -250 to 250, instead of the desired calendar dates.

How can I combine the two datasets in a way that preserves the correct time domain axis?

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

图表按照要求上下排列,但时间轴不再显示日历日期,而是显示类似于0、250'000'000'000、500'000'000'000的值,就像它们展示毫秒一样。此外,时间范围向左侧延伸约30年,绘图数据(从2006年开始)在极右侧开始,并且被大幅压缩。

如何保留域轴(2006年至2012年之间的日历日期)的正确表示?


请编辑您的问题,更正标识符并提供一个 sscce,以展示您所描述的问题。 - trashgod
1个回答

9
我终于自己找到了解决问题的方法:
当我初始化CombinedDomainXYPlot时,它会分配一个默认的numberAxis,而不使用子图已定义的轴。
因此,我必须告诉plot,该领域轴是时间序列:
ValueAxis domainAxis = new DateAxis("");
plot.setDomainAxis(domainAxis);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接