【问题标题】:retrieve data set having only a ChartPanel reference (Java + JFreeChart)检索只有 ChartPanel 引用的数据集 (Java + JFreeChart)
【发布时间】:2011-08-24 08:59:59
【问题描述】:

这个问题与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..

这可能吗?有人能把我引向正确的方向吗?

提前致谢

【问题讨论】:

    标签: java dataset jfreechart


    【解决方案1】:

    最简单的方法是使dataset 引用可用于视图,如here 所示。或者,您可以从ChartPanel 向下钻取,如下所示。

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

    【讨论】:

    猜你喜欢
    • 2012-05-03
    • 2016-02-05
    • 1970-01-01
    • 2016-09-25
    • 2013-02-15
    • 1970-01-01
    • 2012-09-28
    • 1970-01-01
    • 2014-10-14
    相关资源
    最近更新 更多