Currently I use jfreechart through swt. The current problem is tens of thousands of files (currently between 10,000 and 20,000, up to 100,000 later)
I currently use DefaultXYDataset
and XYLineAndShapeRenderer
to load data after opening a file.
There are a few problems:
The chart on the screen is not immediate (within seconds). Work with setchart in the current file open listener.
When resizing the shell, there is a delay in drawing the chart. This causes the program to run slowly.
The jfreechart zoom function and mouse drag events are slow.
My questions:
Is there a quick way to draw when redrawing a new data chart in
chartcomposite
?Essentially, is
XYLineAndShapeRenderer
not good at rendering tens of thousands of data? If so, what is the best method?There is a slight speedup using
fastscatterplot
but I want the line to be a line rather than a dot. Is there a way to linefastscatterplot
?
This is my test code. The screen works very slowly even with 100,000 datasets. Are there speed issues in your current code?
import java.awt.BasicStroke;
import java.awt.Color;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.experimental.chart.swt.ChartComposite;
public class TestGui {
private JFreeChart chart;
private ChartComposite frame;
public static void main(String[] args) {
try {
TestGui window = new TestGui();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
Display display = Display.getDefault();
Shell shell = new Shell();
shell.setSize(600, 400);
shell.setText("SWT Application");
shell.setLayout(new GridLayout(1, false));
// create
chart = createChart(createDataset(getSeries()));
// using chartcomposite
frame = new ChartComposite(shell, SWT.NONE, chart, true);
frame.setDisplayToolTips(false);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.widthHint = 600;
data.heightHint = 366;
frame.setLayoutData(data);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
//making chart
private JFreeChart createChart(XYDataset dataset){
JFreeChart chart = ChartFactory.createXYLineChart(
"", "x", "y", dataset,
PlotOrientation.VERTICAL, false, false, false);
XYPlot plot = chart.getXYPlot();
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
renderer.setSeriesPaint(0, Color.RED);
int seriesCount = plot.getSeriesCount();
for (int i = 0; i < seriesCount; i++) {
plot.getRenderer().setSeriesStroke(i, new BasicStroke(0));
}
plot.setRenderer(renderer);
plot.setBackgroundPaint(Color.white);
plot.setRangeGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.BLACK);
plot.setDomainGridlinesVisible(true);
plot.setDomainGridlinePaint(Color.BLACK);
return chart;
}
private XYDataset createDataset(double[] x) {
XYSeries series = new XYSeries("");
for(int i = 0; i<x.length; i++) {
series.add(i,x[i],false);
}
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series);
return dataset;
}
private static double[] getSeries() {
double[] series = new double[104857];
for(int i = 0; i < series.length; i++) {
series[i] = Math.sin(i * 33 * Math.PI / series.length) + Math.sin(i * 15 * Math.PI / series.length);
}
return series;
}
}