Menu

#240 CategoryStackAreaRender error Printing Area

open
nobody
None
5
2009-03-11
2009-03-11
No

When you try to create a CategoryStackAreaChart using two series ad some information to the first series and the add the second series with a constant value and then add some extra data to the first serie having zero value at the beginning the graph generated is wrong. Because the second series steal some of the area which should form part of the area for the first series. This error is due to the adjustment to zero in one of the edges in the creation of the polygons with create the chart.

Here is a example of the code that fails and a path to solve the problem.

DefaultCategoryDataset dataset= new DefaultCategoryDataset\(\);

dataset.addValue\(Long.valueOf\(0\),"1",Long.valueOf\(1\)\);        
    for\(int i = 1; i <= 5; i++\)
    \{
         dataset.addValue\(Long.valueOf\(10\),"2",Long.valueOf\(i\)\);

    \}
    dataset.addValue\(Long.valueOf\(0\),"1",Long.valueOf\(1\)\);
dataset.addValue\(Long.valueOf\(40\),"1",Long.valueOf\(2\)\);
dataset.addValue\(Long.valueOf\(0\),"1",Long.valueOf\(3\)\);
dataset.addValue\(Long.valueOf\(20\),"1",Long.valueOf\(4\)\);
dataset.addValue\(Long.valueOf\(0\),"1",Long.valueOf\(5\)\);

chart.setBackgroundPaint(null);
return chart;

final JFreeChart chart = ChartFactory.createStackedAreaChart\(

"Stacked Area Chart", // chart title
"Category", // domain axis label
"Value", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true,
false
);

PATCH:

### Eclipse Workspace Patch 1.0
#P JfreeChart
Index: source/org/jfree/chart/renderer/category/StackedAreaRenderer.java
===================================================================
--- source/org/jfree/chart/renderer/category/StackedAreaRenderer.java (revision 1885)
+++ source/org/jfree/chart/renderer/category/StackedAreaRenderer.java (working copy)
@@ -263,7 +263,7 @@
float transStack1 = (float) rangeAxis.valueToJava2D(stack1[1],

dataArea, edge1);

float transStackLeft = (float) rangeAxis.valueToJava2D(

- adjStackLeft[1], dataArea, edge1);

+ stackLeft[1], dataArea, edge1);

// LEFT POLYGON

if (y0 >= 0.0) {

@@ -284,7 +284,7 @@
}

float transStackRight = (float) rangeAxis.valueToJava2D(

- adjStackRight[1], dataArea, edge1);

+ stackRight[1], dataArea, edge1);

// RIGHT POLYGON

if (y2 >= 0.0) {

double yright = (y1 + y2) / 2.0 + stackRight[1];

Discussion

  • Noé Rodríguez González

    The wrong chart of the example and the correct result obtained after apliying the patch

     
  • Noé Rodríguez González

    The wrong chart of the example and the correct result obtained after apliying the patch JPG

     
  • Noé Rodríguez González

    • summary: CategoryStackAreaRender error calculating area --> CategoryStackAreaRender error Printing Area
     

Log in to post a comment.