我有一个二维数组,包含超过10万条记录。当我尝试绘制图表时-CPU很难加载,没有其他事情发生。我已经检查了所有可能的方式,包括消除锯齿,禁用事件监听器等。没有任何反应。而且我假设性能会在3-5分钟左右(好吧,这是相对的事情,但是我想知道如何达到目标)。

因此,我问是否有一种方法可以正确显示数据?我有两个功能,一个用于指定图表,另一个用于绘图:

    public void plotXYChart(double dArray[][], String sPlotName, String sSeriesName,
        String sRangeName){
    XYSeries series1 = new XYSeries(sSeriesName);
    series1.clear();
    for (int i=0; i< dArray.length; i++){
        series1.add(dArray[i][0], dArray[i][1], false);
    }
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.removeAllSeries();
    dataset.addSeries(series1);
    dataset.setAutoWidth(false);
    dataset.setIntervalWidth(2000);

    chart = ChartFactory.createXYLineChart(sPlotName, sSeriesName, sRangeName,
            dataset, PlotOrientation.VERTICAL, false,
            true, false);

    chart.setAntiAlias(false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.getDomainAxis().setStandardTickUnits(new StandardTickUnitSource());
    plot.getRangeAxis().setStandardTickUnits(new StandardTickUnitSource());

    SamplingXYLineRenderer renderer = new SamplingXYLineRenderer();
    plot.setRenderer(renderer);
    plotChart(sPlotName, chart);
}

    private void plotChart(String sPlotName, JFreeChart chart){

    if (this.cPanel!=null)
        cPanel.setChart(chart);
    else
        cPanel = new ChartPanel(chart);

    cPanel.setAutoscrolls(false);
    cPanel.setDomainZoomable(false);
    cPanel.setRangeZoomable(false);
    cPanel.setRefreshBuffer(false);
    cPanel.setDoubleBuffered(rootPaneCheckingEnabled);
    this.chartFrame.add(cPanel);
    this.chartFrame.pack();
    if (this.chartFrame.isVisible() == false)
        RefineryUtilities.centerFrameOnScreen(this.chartFrame);
    this.chartFrame.setVisible(true);

}

最佳答案

这不是JFreeChart问题。您只是试图绘制太多数据。如果您尝试绘制带有挥杆的100k线,您会感到同样的性能问题。减少数据集。

您也可以尝试解决方法,但是我不确定它是否可以解决。不要显示生成的ChartPanel。而是使用以下方法生成ChartPanel的图像:

Image image = chartPanel.createImage ();


在您喜欢的组件内显示生成的图像。图像的生成时间可能会很高,但是一旦生成,它应该更快地显示它并调整其存储组件的大小。那是因为它是静态图像,并且在显示它时不会调用绘图基元。
当然,通过这种方式,您将松开所有ChartPanel函数,仅获取其图像。

关于java - 在JFreeChart中显示巨大的数据集,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7250334/

10-09 07:06
查看更多