JFreeChart图表渲染问题

发布于 2024-12-02 14:12:55 字数 1970 浏览 3 评论 0原文

这个问题是我上一个问题的延续,与不显示数据相关。在给出建议后,我尝试绘制较小的数据范围。据观察,当我处理不同大小的数据范围时,渲染时间迅速增加。最后一个(或多或少)可接受的数据集(正在加载到内存但不用于绘图)包含 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);
}

我想询问有关渲染时间的改进,因为现在,我一直遇到这个问题。

This question is continue of my previous one, related to non-displaying of data. After the given recommendations, I tried to plot a smaller data range. As it has been observed, when I'm working with the data range of the different size, the rendering time is increasing rapidly. The last (more or less) acceptable data set (that is loading to memory but is not for plotting) contains 16k of values. In case I need to plot only 100 of them, the time of rendering is huge as well.

The plot generation code is as follows:

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

}

The code for JFramePanel that is using for output of chart is the next one:

    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);
}

I'd like to ask about improvement for rendering time, cause now, I stuck with this issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

本宫微胖 2024-12-09 14:12:55

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

或者,您可以查看 SlidingXYDataset此处讨论

First disentangle the model and view, then you can page manageable portions of the data into view, as suggested here.

Alternatively, you might look into SlidingXYDataset, discussed here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文