【问题标题】:JFreeChart chart rendering issueJFreeChart 图表渲染问题
【发布时间】:2011-09-01 10:52:45
【问题描述】:

这个问题是我上一个问题的继续,与non-displaying of data 有关。在给出建议之后,我尝试绘制一个较小的数据范围。正如已经观察到的那样,当我处理不同大小的数据范围时,渲染时间正在迅速增加。最后一个(或多或少)可接受的数据集(加载到内存但不用于绘图)包含 16k 个值。如果我只需要绘制 100 个,渲染时间也很长。

情节生成代码如下:

public void plotXYChart(double dArray[][], String sPlotName, String sSeriesName,
        String sRangeName, int iInitialPoint, int iPlotLength){

    XYSeries series1 = new XYSeries(sSeriesName);
    series1.clear();
    series1.setNotify(false);

    if (iInitialPoint+iPlotLength > dArray.length){
        iPlotLength = dArray.length;
    } else {
        iPlotLength+=iInitialPoint;
    }
    for (int i=iInitialPoint; i < iPlotLength; i++){
        series1.add(dArray[i][0], dArray[i][1], false);
    }

    System.out.println("Elements in series: " + series1.getItemCount());

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.removeAllSeries();
    dataset.addSeries(series1);
    System.out.println("Elements in dataset: " + dataset.getItemCount(0));

    chart = null;
    chart = new JFreeChart(new XYPlot(dataset, new NumberAxis(sSeriesName),
    new NumberAxis(sRangeName), new SamplingXYLineRenderer()));

    plotChart(sPlotName, chart);

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

}

用于图表输出的JFramePanel的代码是下一个:

    private void plotChart(String sPlotName, JFreeChart chart){

    if (this.cPanel!=null) {
        cPanel.setChart(chart);
        }
    else
        cPanel = new ChartPanel(chart, true);


    this.chartFrame.add(cPanel);
    if (this.chartFrame.isVisible() == false){
        RefineryUtilities.centerFrameOnScreen(this.chartFrame);
    }
    this.chartFrame.pack();
    this.chartFrame.setVisible(true);
}

我想问一下渲染时间的改进,因为现在,我一直在纠结这个问题。

【问题讨论】:

    标签: java performance swing rendering jfreechart


    【解决方案1】:

    首先解开模型和视图,然后您可以按照here 的建议将数据的可管理部分分页到视图中。

    或者,您可以查看SlidingXYDataset,讨论here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-25
      • 2019-01-11
      • 1970-01-01
      • 2019-11-07
      • 1970-01-01
      • 2018-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多