4

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 dataset 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

Community
  • 1
  • 1
Heisenbug
  • 38,762
  • 28
  • 132
  • 190

1 Answers1

3

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();
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Here's a related [example](http://stackoverflow.com/questions/5522575/how-can-i-update-a-jfreecharts-appearance-after-its-been-made-visible). – trashgod Aug 24 '11 at 10:47