#1120 StackedXYAreaRenderer displays null values as zero

1.0.x
open
nobody
5
2014-08-18
2013-12-02
Igor Rodriguez
No

StackedXYAreaRenderer displays null values as zero. Displaying a value, even zero, is not appropriate. The problem is even more noticeable with stacked polylines. I'm using version 1.0.16.

See example:

public class StackedPolylineRendererTest {
public static void main( String[] args ) {
final JFreeChart chart = ChartFactory.createStackedXYAreaChart( "Null Values Rendered As Zero", null, null, createDataSet(), PlotOrientation.VERTICAL, true, false, false );
chart.getXYPlot().setRenderer( new StackedXYAreaRenderer(XYAreaRenderer.LINES) );

    final JFrame frame = new JFrame( "Test Rendering Of Null Values" ); 
    frame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );
    frame.setPreferredSize( new Dimension( 800, 600 ) );
    frame.add( new ChartPanel( chart ) );
    frame.pack();
    frame.setVisible( true );
}

private static TableXYDataset createDataSet() {
    final XYSeries s = new XYSeries( "Series", true, false ); //$NON-NLS-1$
    s.add( 1, 1 );
    s.add( 2, 2 );
    s.add( 3, null );
    s.add( 4, 4 );
    s.add( 5, 5 );

    final DefaultTableXYDataset dataSet = new DefaultTableXYDataset();
    dataSet.addSeries( s );

    return dataSet;
}

}

2 Attachments

Discussion

  • simon04
    simon04
    2014-07-26

    Here's a patch for the line case:

    diff --git a/source/org/jfree/chart/renderer/xy/StackedXYAreaRenderer.java b/source/org/jfree/chart/renderer/xy/StackedXYAreaRenderer.java
    index 0f52175..7398e6c 100644
    --- a/source/org/jfree/chart/renderer/xy/StackedXYAreaRenderer.java
    +++ b/source/org/jfree/chart/renderer/xy/StackedXYAreaRenderer.java
    @@ -476,7 +476,9 @@ public class StackedXYAreaRenderer extends XYAreaRenderer
                         double transY0 = rangeAxis.valueToJava2D(y0 + ph0,
                                 dataArea, plot.getRangeAxisEdge());
    
    -                    if (orientation == PlotOrientation.VERTICAL) {
    +                    if (Double.isNaN(y0) || nullPoint) {^M
    +                        // do nothing^M
    +                    } else if (orientation == PlotOrientation.VERTICAL) {^M
                             areaState.getLine().setLine(transX0, transY0, transX1,
                                     transY1);
                         }
    

    What is the expected behaviour for areas? The area polygon has to be closed somehow …
    Remark: XYAreaRenderer is also affected …