【发布时间】:2016-03-26 17:06:19
【问题描述】:
我有一个超过 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);
}
【问题讨论】:
-
我认为不可能在单个图表上完全显示 100k 位数据,并且如果您通过平均或其他方法以某种方式限制数据,您将在更短的时间内获得相同的图表。另外,您是否对您的程序进行了概要分析,以准确了解您的瓶颈在哪里?
-
在显示过程中的某个地方(可能是缩放),其余的都运行正常。问题是我必须使用缩放和原始大小数据,因此我最好自动缩放它。
标签: java performance swing jfreechart