x axis labels on a bar chart

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

x axis labels on a bar chart

Post by Belinda Haughton » Wed Mar 20, 2002 11:33 am

Hi

Could someone please let me know how I can set the x axis labels on a bar chart? In other words, so that I can replace "category 1", "category 2" etc with my own labels.

This is what my plot looks like:

Plot plot = new VerticalBarPlot(new HorizontalCategoryAxis("months"), new VerticalNumberAxis("sales"));

and the dataset is build up as follows:

Number[][] data = new Number[1][5];
data[0][0] = new Integer(20);
data[0][1] = new Integer(25);
data[0][2] = new Integer(27);
data[0][3] = new Integer(22);
data[0][4] = new Integer(24);

DefaultCategoryDataset ds = new DefaultCategoryDataset(data);

This is just a test I am using to see how bar chars work in JFreeChart. I am not sure if I have done the above in the correct way.

Thanks in advance,
Belinda

Belinda

Re: x axis labels on a bar chart

Post by Belinda » Wed Mar 20, 2002 11:38 am

Not to worry - just found the answer myself. Thanks

David Gilbert

Re: x axis labels on a bar chart

Post by David Gilbert » Wed Mar 20, 2002 1:13 pm

There's two ways to handle it:

1) Use this constructor:

public DefaultCategoryDataset(String[] seriesNames, Object[] categories, Number[][] data);

...instead of the one you are using; or

2) Call the following method on the dataset you already have:

public void setCategories(Object[] categories);
...making sure you supply the correct number of categories.

Regards,

DG.

Locked