retrieve data set having only a ChartPanel reference (Java + JFreeChart)
This question in partially related to my previous post on this subject.
I would like to know after a ChartPanel has been constructed :
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;
}
Can I retrieve the d开发者_StackOverflow中文版ataset used for generating chart, but having only a reference to chartPanel?
ChartPanel panel = buildChart();
panel.getDataset; //I'm looking for a way to retrieve the dataset, or XYSeriesCollection..
Is that possible? Can someone put me in the right direction?
thanks in advance
The easiest way is to make a dataset
reference available to the view, as shown here. Alternatively, you can drill down from the ChartPanel
, as suggested below.
ChartPanel chartPanel;
JFreeChart chart = chartPanel.getChart();
XYPlot plot = (XYPlot) chart.getPlot();
XYDataset data = plot.getDataset();
精彩评论