此问题与 my previous post 部分相关关于这个问题。
我想知道在构造了一个 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 的引用吗?
ChartPanel panel = buildChart();
panel.getDataset; //I'm looking for a way to retrieve the dataset, or XYSeriesCollection..
这可能吗?有人能告诉我正确的方向吗?
提前致谢
最佳答案
最简单的方法是使dataset
引用可用于 View ,如图所示here .或者,您可以从 ChartPanel
向下钻取,如下所示。
ChartPanel chartPanel;
JFreeChart chart = chartPanel.getChart();
XYPlot plot = (XYPlot) chart.getPlot();
XYDataset data = plot.getDataset();
关于java - 检索仅具有 ChartPanel 引用的数据集(Java + JFreeChart),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7172882/