只有 ChartPanel 引用的数据集如何检索(Java + JFreeChart)

4
这个问题与我之前发布的关于这个主题的帖子有一定关联。
我想知道在ChartPanel构建完成后:
public ChartPanel buildChart(){
    XYSeriesCollection dataset = new XYSeriesCollection();
...
    FreeChart chart = ChartFactory.createXYLineChart("line chart example",
                "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartPanel = new ChartPanel(chart);
    return chartPanel;
}

我可以通过仅有图表面板的引用来检索用于生成图表的数据集吗?

ChartPanel panel = buildChart();
panel.getDataset; //I'm looking for a way to retrieve the dataset, or XYSeriesCollection..

这个有可能吗?有没有人能把我指引正确的方向?

提前感谢您。

1个回答

3
最简单的方法是将“dataset”引用提供给视图,如这里所示。或者,您可以像下面建议的那样从 ChartPanel 中深入挖掘。
ChartPanel chartPanel;
JFreeChart chart = chartPanel.getChart();
XYPlot plot = (XYPlot) chart.getPlot();
XYDataset data = plot.getDataset();

这里有一个相关的示例 - trashgod

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