开发者

retrieve data set having only a ChartPanel reference (Java + JFreeChart)

开发者 https://www.devze.com 2023-03-30 02:17 出处:网络
This question in partially related to my previous post on this subject. I would like to know after a ChartPanel has been constructed :

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消