JFreeChart works slowly

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
theonlymine
Posts: 1
Joined: Fri Dec 05, 2014 7:40 pm
antibot: No, of course not.

JFreeChart works slowly

Post by theonlymine » Fri Dec 05, 2014 7:44 pm

I create JFreeChart program that can:

- move points of splines
- don't allow to cross black splines (boundary splines)
- create new splines in real-time (as Grapher)
- mouse wheel zoom
For adding new series to dataset I use this function:

Code: Select all

   public static XYSeriesCollection createSplineDataset(File[] polFiles) {
        dataset = new XYSeriesCollection();
        for (File polFile : polFiles) {
            XYSeries series = new XYSeries(polFile.getName());
            Scanner s = null;
            try {
                s = new Scanner(new File(polFile.getAbsolutePath()));
            }catch (FileNotFoundException ex) {
                System.out.println("Scanner error!");
            }
            s.useLocale(Locale.US);
            while (s.hasNext()) {
                float x = s.nextFloat();
                float y = s.nextFloat();
                series.add(x, y);
            }
            dataset.addSeries(series);
        }
        return dataset;
    }
Main program (there 500+ strings of code, so this is part of it):

Code: Select all

public class SplineDemo {
    // declaration of variables
    private static void display(){
        final File[] polFiles = new File("FORPLOT").listFiles();
        polFiles[0] = new File("FORPLOT/InitPolin1");
        polFiles[1] = new File("FORPLOT/InitPolin0");
        for (int i = 2; i <= 36; i++)
            polFiles[i] = new File("FORPLOT/P"+(i-2));
        dataset = JFunc.createSplineDataset(polFiles); // create dataset
        // --------some code-----------
        NumberAxis domain = new NumberAxis("\u03C1");
        NumberAxis range = new NumberAxis("g(\u03C1)");
        SplineRenderer r = new SplineRenderer(20);
        xyplot = new XYPlot(dataset, domain, range, r);
        final XYLineAndShapeRenderer render = (XYLineAndShapeRenderer) xyplot.getRenderer();
        render.setBaseShapesVisible(true);
        final JFreeChart chart = new JFreeChart(xyplot);
        // --------some code-----------            
        chartPanel = new ChartPanel(chart){
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(640, 480);
            }
        };        
        chart.removeLegend();
        chartPanel.addMouseListener(new MouseListener() {
        //------ for creating new splines and to move points of splines ---------
        });

        chartPanel.addMouseWheelListener(new MouseWheelListener() {
        //--------- zoom ------------
        });

        chartPanel.addMouseMotionListener(new MotionListener());

        chartPanel.addChartMouseListener(new ChartMouseListener() {
        //------ for creating new splines and to move points of splines ---------
        });

        chartPanel.setDomainZoomable(false);
        chartPanel.setRangeZoomable(false);
        chartPanel.setPopupMenu(null);
        frame = new JFrame(Title);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(chartPanel);

        //------ buttons -------

        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        frame.addComponentListener(new ComponentListener() {

            @Override
            public void componentResized(ComponentEvent ce) {
            // ---- to move points when window was resized
            }
        });
    }

    public static class MotionListener implements MouseMotionListener {
    //------ to move points -----------
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                display();
            }
        });
    }
}
So, my problem is that when at there are 1-5 splines at the same time plotted, everything works ideally quickly. When them becomes more than 30 splines as on a screenshot, working is decelerated (for example, points aren't in time behind a mouse in case of moving, zoom works slower, etc.). In what the problem can consist? Here the report from YourKit, but I don't understand it. Slowly the new draw of all diagrams or what works?

I don't understand how 30 diagrams can already brake so. What will be in case of 100+? If it is necessary, I can throw off a full code and project in zip archive.
Image
Image

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: JFreeChart works slowly

Post by John Matthews » Mon Dec 08, 2014 12:21 am

Cross-posted here.

Locked