BarChart line widths

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
ben_ross
Posts: 5
Joined: Wed Aug 13, 2003 1:53 pm

BarChart line widths

Post by ben_ross » Wed Aug 20, 2003 2:31 pm

I've seen this question repeated a few times, but I can't seem to get it working. I am trying to do a bar chart that has many categories. The bar chart looks okay with just a few, but as the number of categories increase, the line width becomes too small to see on the screen (or atleast a projector). There seem to be two problems.

1) The white space between the lines stays constant, no matter what value I put into the setCategoryMargin() method. Is there a way to make the lines touch (no white space between)? Changing the Lower and Upper Margins appears to have the expected result, but the Category Margin doesn't change the line width.

2) The axis category labels do not appear to be staying lined up with the actual line on the plot. When there are many categories, this causes the chart to become very difficult to read. In fact when I set the Upper and Lower Margins to 0 on the axis, the labels appeared to show up still indented, so they did not match the lines at all. Any ideas here?

thanks

Ben

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Aug 20, 2003 5:54 pm

Can you post an image or a small sample application?
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

ben_ross
Posts: 5
Joined: Wed Aug 13, 2003 1:53 pm

Post by ben_ross » Thu Aug 21, 2003 4:37 pm

David,

Here are two images a horizontal and vertical bar chart. As you can see the bars seem to get pretty skinny compared to the whitespace. Also, the labels on the axis don't seem to quite match-up with the lines.

This is the only customization I have done:
...
CategoryPlot plot = chart.getCategoryPlot();
CategoryAxis axis = plot.getDomainAxis();
axis.setVerticalCategoryLabels(true);
axis.setCategoryMargin(0.001);
axis.setUpperMargin(0.05);
axis.setLowerMargin(0.05);
chart.setLegend(null);
chart.setBackgroundPaint(this.getBackground());
...

Regardless of what I set the Category Margin to, the behavior is the same.

Image
Image

thanks,

Ben

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Aug 21, 2003 5:42 pm

The problem is in your dataset. Rather than one series with 21 categories, you in fact have 21 series with 21 categories...a lot of bars are being drawn with a value of zero. So you need to take a closer look at how you are creating your dataset.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

ben_ross
Posts: 5
Joined: Wed Aug 13, 2003 1:53 pm

BarChart widths

Post by ben_ross » Thu Aug 21, 2003 7:38 pm

Thanks, the series thing did it. I think I had changed it awhile back trying to get a Legend that looked right, but the legend was really not necessary.

When having all of the separate lines in the same series, is there an easy way to make the lines of the chart different colors?

thanks a lot,

Ben

nurettin
Posts: 2
Joined: Mon Aug 04, 2003 8:25 am

Post by nurettin » Mon Sep 15, 2003 9:45 am

Hello,
I have the same problem and I do not know how to set the data.

I set the data as follows :

DefaultCategoryDataset data = new DefaultCategoryDataset();

for (int i = 0; i < clones.length ; i++)
{
data.addValue(numbers[i], Integer.toString(i) , groupNames[i]);
}

Thanks...
nurettin

Guest

Post by Guest » Mon Sep 15, 2003 11:16 am

Hi,
I found the solution..

Thanks..

nurettin

Locked