Series shape rendering doesn't respect SeriesRenderingOrder

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
colomb
Posts: 15
Joined: Fri May 29, 2009 8:10 pm

Series shape rendering doesn't respect SeriesRenderingOrder

Post by colomb » Fri May 31, 2019 12:20 am

Example: There are two series in the XYSeriesCollection. Both represent the same line, but one has more point defined between the endpoints. The series with more points is added to the collection after the one with fewer points. The one with fewer points is rendered with a stroke. I would expect the line to be drawn from the first series to be over the points from the second series, but it is not. The points from the first series are over the points from the second series, but the line is not. Reversing the order they are added to the collection and/or setting the rendering order to be Forward does not help.

This can be worked around by using separate Datasets, but I'd like to know if this is a bug, or if I'm setting the Renderer/Dataset incorrectly for the behavior I'm looking for.

Code: Select all

public class DrawingOrder extends ApplicationFrame
{
    JPanel chartPanel;

    public DrawingOrder()
    {
        super( "DrawingOrder" );
        XYDataset data = createData();
        JFreeChart chart = createChart( data );
        chartPanel = new ChartPanel( chart );
        chartPanel.setPreferredSize( new Dimension( 600, 400 ) );
        setContentPane( chartPanel );
    }

    private JFreeChart createChart( XYDataset dataSet )
    {
        JFreeChart chart = ChartFactory.createXYLineChart( "Drawing Order", "X", "Y", dataSet, PlotOrientation.VERTICAL, true, false, false );

        XYLineAndShapeRenderer renderer = ( XYLineAndShapeRenderer ) chart.getXYPlot().getRenderer();
        renderer.setSeriesLinesVisible( 1, false );
        renderer.setSeriesShapesVisible( 1, true );
        renderer.setSeriesShapesVisible( 0, true );

        return chart;
    }

    private XYDataset createData()
    {
        XYSeriesCollection dataSet = new XYSeriesCollection();

        XYSeries lineSeries = new XYSeries( 0, false, true );
        lineSeries.add( 0, 0 );
        lineSeries.add( 4, 4 );
        dataSet.addSeries( lineSeries );

        XYSeries pointSeries = new XYSeries( 1, false, true );
        pointSeries.add( 0, 0 );
        pointSeries.add( 1, 1 );
        pointSeries.add( 2, 2 );
        pointSeries.add( 3, 3 );
        pointSeries.add( 4, 4 );
        dataSet.addSeries( pointSeries );

        return dataSet;
    }

    public static void main( String[] args )
    {
        SwingUtilities.invokeLater( () ->
        {
            DrawingOrder drawingOrder = new DrawingOrder();
            drawingOrder.pack();
            drawingOrder.setVisible( true );
        } );
    }
}

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

Re: Series shape rendering doesn't respect SeriesRenderingOrder

Post by John Matthews » Fri May 31, 2019 6:39 pm

XYLineAndShapeRenderer renders lines and shapes in separate passes. You might look at other implementations of XYItemRenderer, such as StandardXYItemRenderer.

colomb
Posts: 15
Joined: Fri May 29, 2009 8:10 pm

Re: Series shape rendering doesn't respect SeriesRenderingOrder

Post by colomb » Tue Jun 04, 2019 4:06 pm

John,

Yup, the StandardXYItemRenderer does respect the rendering order for both the shapes and the lines. Thank you!

Locked