2

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:

   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):

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, @trashgod adviced here to modify useBuffer but it didn't help me. 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

30 splines YourKit

Community
  • 1
  • 1
Denis
  • 503
  • 8
  • 32
  • 1
    ~10^5+ points?! I don't see an easy fix, except perhaps to switch renderers, limit detail or control visibility, for [example](http://stackoverflow.com/a/11895709/230513). – trashgod Nov 25 '14 at 23:49
  • 1
    Frankly: This is not what JFreeChart is intended for. It is intended for painting "nice looking" charts, smooth and with tick marks and all such. If you want to draw "many" such lines, you won't be able to see anything anyhow, and from a purely "information visualization" point of view, you'd rather employ some *edge bundling* algorithm or so (web search for this term, if necessary). You might be able to paint **many** more curves if you did it manually, with own, hand-crafted `Path2D` objects, but the resuld would be that you won't see anything except some chaotic bunch of lines... – Marco13 Nov 27 '14 at 19:34
  • Cross-posted [here](http://www.jfree.org/forum/viewtopic.php?f=3&t=117120). – trashgod Dec 07 '14 at 23:22

1 Answers1

1

The XYSplineRenderer "connects data points with natural cubic splines." Not unexpectedly, its performance scales poorly for thousands points. If the goal is to render smoothed data, it may be advantageous to do the interpolation in the background, as suggested here, and revert to the parent XYLineAndShapeRenderer for rendering only.

In addition, scores of curves, each having hundreds of points, may be difficult to distinguish visually. Consider controlling the visibility of related series, a shown in this example that uses JCheckBox to toggle the display of individual series.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045