1
\$\begingroup\$

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:

  1. The chart on the screen is not immediate (within seconds). Work with setchart in the current file open listener.

  2. When resizing the shell, there is a delay in drawing the chart. This causes the program to run slowly.

  3. The jfreechart zoom function and mouse drag events are slow.

My questions:

  1. Is there a quick way to draw when redrawing a new data chart in chartcomposite?

  2. Essentially, is XYLineAndShapeRenderer not good at rendering tens of thousands of data? If so, what is the best method?

  3. 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 line fastscatterplot?

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

}
\$\endgroup\$
1
  • \$\begingroup\$ Please edit your question so that the title describes the purpose of the code, rather than its mechanism. We really need to understand the motivational context to give good reviews. Thanks! \$\endgroup\$ – Toby Speight Nov 29 '19 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.