2011-08-24 23 views
4

此问题部分与此主题的my previous post有关。检索仅具有ChartPanel参考的数据集(Java + JFreeChart)

我想知道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.. 

这可能吗?有人能让我走向正确的方向吗?

由于事先

回答

3

最简单的方法是使参考dataset提供给视图,如图所示here。或者,您可以从ChartPanel向下钻取,如下所示。

ChartPanel chartPanel; 
JFreeChart chart = chartPanel.getChart(); 
XYPlot plot = (XYPlot) chart.getPlot(); 
XYDataset data = plot.getDataset(); 
+0

这是一个相关的[示例](http://stackoverflow.com/questions/5522575/how-can-i-update-a-jfreecharts-appearance-after-its-been-made-visible)。 – trashgod

+0

+1:非常感谢。 – Heisenbug