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
BarChart line widths
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Can you post an image or a small sample application?
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


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.


thanks,
Ben
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.


thanks,
Ben
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


BarChart widths
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
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