Barcharts - differnet series grouping?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
gax

Barcharts - differnet series grouping?

Post by gax » Fri Aug 20, 2004 10:53 pm

Hi, I want to make a bar chart where all the data from each series is grouped into its own separate category. So, all series 1 red bars together, then all series 2 blue bars, then series 3 all together and so on.

Here's an example of what I"m trying to do:
http://home.comcast.net/~cwpllc/example.png

I've tried a lot of different things by tweaking the examples but haven't figured it out yet. Any clues on how/if I can do this in JFreeChart?
Thanks!
-John

Steve
Posts: 53
Joined: Mon Dec 22, 2003 8:29 pm

Post by Steve » Mon Aug 23, 2004 4:55 pm

Create your dataset with a 2d array in this fassion:

Code: Select all

double data = new double[3][i]; // where i is the # of elements displayed.
The first dimension will be your "Category".
The second dimension will be the data.

So the first bar of the first category would be:

Code: Select all

data[0][0] = 309.23;
Or the 3rd bar in the 2nd category:

Code: Select all

data[1][2] = 89.3;

Guest

Post by Guest » Tue Aug 24, 2004 9:35 pm

OK thanks!

So using your info:

Code: Select all

double data[][] =
        {{1,2,3,4}, {3,2,1,4}, {4,2,1,3}};
        
CategoryDataset ds = DatasetUtilities.createCategoryDataset("rowKey", "dataKey", data);

JFreeChart chart = ChartFactory.createBarChart(
            "Bar Chart Demo 8",       // chart title
            "Category",               // domain axis label
            "Value",                  // range axis label
            ds,                  // data
            PlotOrientation.VERTICAL, // orientation
            false,                    // include legend
            true,                     // tooltips?
            false                     // URLs?
        );
I get this:
http://home.comcast.net/~cwpllc/example2.png

which is pretty close to what I want.

Is there any way to now turn all the bars for dataKey1 to red, all the bars for dataKey2 to blue, and so on? (same color for each dataKey grouping)

thanks a ton!
-John

Steve
Posts: 53
Joined: Mon Dec 22, 2003 8:29 pm

Post by Steve » Thu Aug 26, 2004 8:11 pm

I believe you use the setSeriesPaint() method for that.
It's under the renderer or the plot classes.

zobi13
Posts: 7
Joined: Mon Aug 01, 2005 9:24 pm

Post by zobi13 » Fri Aug 05, 2005 9:37 pm

Please,
i would like to know how you made with a XYDataset and not with a CategoryDataset. Indeed, i have a XYBarChart with Timeseries. So, i must use a XYDataset. My goal is to made a barchart with timeseries, and each series grouped into its own separate category.

Thanks for reply.

Locked