#876 'NoNegativeZero'-Bug in StackedBarRenderer3D.java

General (896)

We just discovered an error in StackedBarRenderer3D.
It seems like series-color and -labels are wrong if there are 2 or more negative values present.

The error can be reproduced using the following data (more detailed code in the attached zip):

dataSet = new DefaultCategoryDataset();

// example data that will be display with wrong
// colors & labels (if StackedBarRenderer3D not fixed)
dataSet.setValue(-1.0, "series1", "category1");
dataSet.setValue(-4.0, "series2", "category1");
dataSet.setValue(-7.0, "series3", "category1");

dataSet.setValue(-2.0, "series1", "category2");
dataSet.setValue(-5.0, "series2", "category2");
dataSet.setValue(8.0, "series3", "category2");

dataSet.setValue(-2.0, "series1", "category3");
dataSet.setValue(5.0, "series2", "category3");
dataSet.setValue(-8.0, "series3", "category3");

dataSet.setValue(-3.0, "series1", "category4");
dataSet.setValue(6.0, "series2", "category4");
dataSet.setValue(9.0, "series3", "category4");
dataSet.setValue(-9.0, "series4", "category4");

// example data that will be display correct
dataSet.setValue(3.0, "series1", "category5");
dataSet.setValue(6.0, "series2", "category5");
dataSet.setValue(9.0, "series3", "category5");

dataSet.setValue(2.0, "series1", "category6");
dataSet.setValue(-5.0, "series2", "category6");
dataSet.setValue(-8.0, "series3", "category6");

dataSet.setValue(2.0, "series1", "category7");
dataSet.setValue(5.0, "series2", "category7");
dataSet.setValue(-8.0, "series3", "category7");

dataSet.setValue(2.0, "series1", "category8");
dataSet.setValue(-5.0, "series2", "category8");
dataSet.setValue(8.0, "series3", "category8");

We were able to fix it by changing the following code in protected void drawStackVertical(...) and protected void drawStackHorizontal(...)

int series = 0;
if (curr[0] == null) {
series = -((Integer) prev[0]).intValue();
} else {
series = ((Integer) curr[0]).intValue();
// FIXME (quick fix by iba): error was here: there is no
// distinction possible between -0 and +0 (series),
// so we us the value instead
// if (series < 0) {
if (((Double) curr[1]).doubleValue() < 0.0) {
series = -((Integer) prev[0]).intValue();

The error in short form:
prev[0] and curr[0] are storing the series-index (a negative index for "negative values" and a positive index for "positive values"). But there is no way to do the same distinction using 0 (+0/-0).

(the fixed StackedBarRenderer3D.java can be found attached zip too)

Best regards,

Volker Boehlke
iba Consulting Gesellschaft


  • Nobody/Anonymous

    Demo for bug-reproduction and fixed StackedBarRenderer3D.java

  • David Gilbert

    David Gilbert - 2008-08-15

    Logged In: YES
    Originator: NO

    Thanks for the report. I'll fix this now...

  • David Gilbert

    David Gilbert - 2008-08-15
    • priority: 5 --> 9
    • assigned_to: nobody --> mungady
  • David Gilbert

    David Gilbert - 2008-08-15
    • status: open --> closed-fixed
  • David Gilbert

    David Gilbert - 2008-08-15

    Logged In: YES
    Originator: NO

    I committed a fix to Subversion for inclusion in the 1.0.11 release.


    Dave Gilbert
    JFreeChart Project Leader


Log in to post a comment.