Stacked area chart is split into bars

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
toblix
Posts: 5
Joined: Sat Jun 30, 2007 12:25 am

Stacked area chart is split into bars

Post by toblix » Tue Aug 05, 2008 7:33 am

I'm trying to get a stacked area graph going like in this example here. I assume the example was based on an older version of JFreeChart, but I still think the code should make sense. I'm currently running this exact code:

Code: Select all

CategoryDataset dataset = DatasetUtilities.createCategoryDataset(
            "Series ", "Type ", new double[][] {
                    {1.0, 4.0, 3.0, 5.0, 5.0, 7.0, 7.0, 8.0 },
                    {5.0, 7.0, 6.0, 8.0, 4.0, 4.0, 2.0, 1.0 },
                    {4.0, 3.0, 2.0, 3.0, 6.0, 3.0, 4.0, 3.0 }
                }
        );
    	
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
            );

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ChartUtilities.writeChartAsPNG(baos, chart, 1000, 450);
baos.close();
byte[] imageData = baos.toByteArray();
return imageData;
The image date is later sent to a browser, but look at it:
Image

I haven't found any posts about similar problems. Could it be the way the chart is rendered?

edit:
I just tried the exact example code, with the ChartPanel and everything, and got this:

Image

By the way, I got the problem with 1.0.6, but upgrading to 1.0.10 and jcommon-1.0.13 didn't change anything.

edit:
Also, the error appears on both Java 1.5.0_15 and 1.6.0_07

toblix
Posts: 5
Joined: Sat Jun 30, 2007 12:25 am

Post by toblix » Tue Aug 05, 2008 8:15 am

I see from the source that this is probably a known issue:

Code: Select all

// FIXME: calculate xxLeft and xxRight
Is there a known way to circumvent this, possibly by reducing the spacing between the "bars"? Also, there's the white line in the middle of each bar.

samoht
Posts: 12
Joined: Wed Jun 18, 2008 12:25 pm
Location: Norway

Post by samoht » Thu Aug 07, 2008 2:55 pm

frame.getChartPanel().getChart().getCategoryPlot().getDomainAxis().setCategoryMargin(0);

I think this would work

cardybean
Posts: 8
Joined: Tue Dec 10, 2013 2:45 pm
antibot: No, of course not.

Re:

Post by cardybean » Mon Dec 30, 2013 10:10 am

samoht wrote:frame.getChartPanel().getChart().getCategoryPlot().getDomainAxis().setCategoryMargin(0);

I think this would work
I was having the same issue, scoured the API/code but couldn't figure out what I was doing wrong. I confirm your solution works :). I personally used this:

Code: Select all

plot.getDomainAxis().setCategoryMargin(0);

Locked