嗨,我有一个JFreeChart
我希望能够在不丢失旧数据的情况下绘制和添加系列。
例如,我最初生成JFreeChart
来自:
public JFreeChart plot(Number[] x, Number[] y, String title, String xLabel,
String yLabel) {
XYSeries series = new XYSeries(title);
if (x.length == y.length) {
for (int i = 0; i < x.length; i++) {
series.add(x[i], y[i]);
}
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series);
JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel,
yLabel, dataset, PlotOrientation.VERTICAL, false, false,
false);
return chart;
} else {
System.out.println("Error: [plot] X&Y Vectors of different lengths");
return null;
}
}
然后我会将它添加到 aChartPanel
和我的ContentPane
:
ChartPanel cp = new ChartPanel(chart);
contentPane.add(cp, BorderLayout.CENTER);
现在我需要一个可以在不忘记数据集中已经存在的系列的情况下向绘图添加额外系列的函数(所以我不能再次调用我的绘图函数)
我该怎么做呢?