Plotting two XYSeriesCollection not working.

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
arwelbath
Posts: 24
Joined: Fri Aug 10, 2007 12:37 pm

Plotting two XYSeriesCollection not working.

Post by arwelbath » Tue Nov 13, 2007 6:12 pm

Hi,
I'm trying to make a plot from two XYSeriesCollections on one graph. The first collection should be rendered as points, and the second collection (which are best fits to the points) as lines. But, when I try it as shown below, only the lines plot (i.e. the first collection is not shown). What am I doing wrong?
Cheers,
Arwel

Code: Select all

        public ChartPanel mkPointsAndLinesSemilogChart(XYSeriesCollection pointsColl, XYSeriesCollection linesColl, String name) {
        NumberAxis xAxis = new NumberAxis("Qz");
        LogarithmicAxis yAxis = new LogarithmicAxis("Ref");
        yAxis.setStrictValuesFlag(false);
        
        //Make the symbols plot....
        XYLineAndShapeRenderer rendererPoints = new XYLineAndShapeRenderer();
        rendererPoints.setShapesVisible(true);
        rendererPoints.setShapesFilled(false);
        rendererPoints.setLinesVisible(false);

        //Make the lines plot....
        XYLineAndShapeRenderer rendererLines = new XYLineAndShapeRenderer();
        rendererLines.setLinesVisible(true);
        rendererLines.setShapesVisible(false);
        
        FastXYPlot plot = new FastXYPlot(pointsColl, xAxis, yAxis, rendererPoints);
        plot.setBackgroundPaint(Color.white);
        plot.setDomainGridlinesVisible(false);
        plot.setRangeGridlinesVisible(false);
        
        plot.setDataset(1,linesColl);
        plot.setRenderer(1,rendererLines);
        
        JFreeChart chart = new JFreeChart("Reflectivity", plot);
        chart.removeLegend();
        chart.setAntiAlias(false);
        final ChartPanel panel = new ChartPanel(chart);
        ch = chart;
        return panel;
    }

arwelbath
Posts: 24
Joined: Fri Aug 10, 2007 12:37 pm

Post by arwelbath » Tue Nov 13, 2007 6:18 pm

Okay, if I use the renderLines renderer for both plots, they both display. So the problem seems to be with 'rendererPoints'. I can't quite see what though.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Nov 14, 2007 12:11 pm

Perhaps the problem is in FastXYPlot, which is not part of JFreeChart.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

arwelbath
Posts: 24
Joined: Fri Aug 10, 2007 12:37 pm

Post by arwelbath » Wed Nov 14, 2007 1:00 pm

Yes, I've worked out that much now, and it works fine with XYPlot. However, I have a problem which is suffering from a performance issue (i.e. a few hundred points updating several times every second), hence my interest in FastXYPlot.
Now that I've realised that's the issue, I've added a question to the 'To those who use JfreeChart for Dynamic Plots/Large Sets' thread to see if not being able to use multiple renderers in one chart is a bug in fastXYPlot.

Priya Shivapura
Posts: 59
Joined: Fri Feb 23, 2007 7:41 am

Post by Priya Shivapura » Tue Feb 05, 2008 8:26 pm

There are two passes through the drawItem of the XYLineAndShapeRenderer. The 1st one draws the lines and the second draws the shapes.

In the FastXYPlot, a HashSet stores the item that has been drawn. So, when you use the "rendererPoints" renderer, the hashset stores the dataItem during the 1st pass (when it tries to draw the line). During the second pass to draw the shapes, it's not drawn as the dataItem exists in the HashSet.

Clearing the HashSet before every pass solves this problem.

Regards,
Priya

arwelbath
Posts: 24
Joined: Fri Aug 10, 2007 12:37 pm

Post by arwelbath » Wed Feb 06, 2008 9:01 am

Hi Priya,
Yes! that seems to have worked very well. Many thanks!
Cheers,
arwel

Locked