Area vs StackedArea strange different behaviour

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Fabrice
Posts: 13
Joined: Fri Apr 23, 2004 8:37 am
Location: France

Area vs StackedArea strange different behaviour

Post by Fabrice » Fri Apr 23, 2004 8:42 am

Hello,

Here is a sample code for the StackedArea and Area charts.
I've found a different behaviour for these two charts.

Code: Select all

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.CategoryDataset;
import org.jfree.data.DatasetUtilities;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

public class AreaBehaviour extends ApplicationFrame {

  public AreaBehaviour(String title) {

    super(title);

    double[][] data = new double[][] {
      {4.0, 3.0, 2.0, 3.0, 6.0, 3.0, 4.0, 3.0 }};

    CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data);

    JFreeChart chart = ChartFactory.createStackedAreaChart(
      "Stacked Area Chart",
      "Category",
      "Value",
      dataset,
      PlotOrientation.VERTICAL,
      true,
      true,
      false
    );

    // add the chart to a panel...
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
  }

  public static void main(String[] args) {
    StackedAreaChartDemo demo = new StackedAreaChartDemo("Stacked Area Chart Demo");
    demo.pack();
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.setVisible(true);
  }
}
Just run the code now and look at the first and last point of this chart.
The begining and ending lines of this chart are vertical.

Now just replace

Code: Select all

    JFreeChart chart = ChartFactory.createStackedAreaChart(
by

Code: Select all

    JFreeChart chart = ChartFactory.createAreaChart(
Then run the code and look again at the first and last point of this chart.
The begining and ending lines of the chart aren't vertical now.
It seems that the Area chart begins from a point having a zero range value.

Is this a normal behaviour or a real problem ?

Thanks in advance,

Fabrice

Fabrice
Posts: 13
Joined: Fri Apr 23, 2004 8:37 am
Location: France

Post by Fabrice » Fri Apr 23, 2004 10:26 am

Here are the results I obtained with this source code

For the StackedArea :
Image

For the Area :
Image

I think it's a better way to show you the problem (It was hard to find a free hosting service with FTP access that I can reach from work to put these pictures on...)

Fabrice

Fabrice
Posts: 13
Joined: Fri Apr 23, 2004 8:37 am
Location: France

Post by Fabrice » Mon Apr 26, 2004 2:32 pm

Am I the only one having trouble with this ?

I'm using JFreeChart 0.9.18

The real big problem I have is when I want more than one array, and when one array comes over another.
I can't use a StackedArea here.

Here's the result I get with another test...
Image

It's not really beautiful...

It seems to be a rendering problem.
Is there a flag somewhere to tell the Area to draw vertical lines for its first and last points ?

Can someone help me ?

Fabrice

guest

Area Chart - have u got ur problem solved?

Post by guest » Fri Sep 17, 2004 11:05 am

hii.,

I am facing the same problem with Area chart regarding the start and end point starts with zero. I want it to start with the value in the dataset.

Any solution ??

regards
guest

guest

problem solved

Post by guest » Fri Sep 17, 2004 11:21 am

Hii,

After muddling thru the source code. I came to know that the AreaRenderer has a method EndType. Which actually sets the end type for the area chart. It is default to TAPER. One can use TRUNCATE to get rid of zero start and end point.

regards
guest

Fabrice
Posts: 13
Joined: Fri Apr 23, 2004 8:37 am
Location: France

Post by Fabrice » Mon Sep 20, 2004 3:19 pm

Great !!!

Adding this code after the chart instanciation will give the same behaviour between AreaRenderer and StackedAreaRenderer.

Code: Select all

CategoryPlot plot = chart.getCategoryPlot();
AreaRenderer renderer = (AreaRenderer)plot.getRenderer();
renderer.setEndType(AreaRendererEndType.TRUNCATE);
(the imports may vary with the JFreeChart version)

Thanks for this help !

Locked