If you have a chart that shows percentages, you obviously have a range axis
0% to 100% => range min value = 0.0, range max value = 100.0. For this
reason we also don't want to have auto calculated range-axes but a fixed
range 0.0 - 100.0 because the axes line shouldn't go higher than the 100 %
max value. If you now have a category value of e.g. 99.5% and switch on the
item labels, this label gets cut of at the top border. (Of course also
depending on the font).
The item labels should be drawn independently of the inner plot border, so
that such labels don't get cut but are drawn over the borders of the inner
plot.
Test chart:
-----------------------------
/**
* This test shows that a bar label gets cut by the plots top border if
a fixed range is used without margins and the bar is "too high" for the
label.
* (E.g. for percenatge charts 0% to 100% you don't want margins but an
exact range axis from 0% to 100% and not wider.)
*
* @return JFreeChart.
*/
private JFreeChart testBarLabelCut() {
JFreeChart result = null;
DefaultCategoryDataset cd = new DefaultCategoryDataset();
cd.addValue(50.3, "Series1", "Category1");
cd.addValue(99.99, "Series1", "Category2");
result = ChartFactory.createBarChart("Bar Chart", "Categories",
"Values", cd, PlotOrientation.VERTICAL, false, false, false);
CategoryPlot plot = result.getCategoryPlot();
plot.getRangeAxis().setUpperMargin(0.0);
CategoryItemRenderer renderer = plot.getRenderer();
CategoryItemLabelGenerator generator = new
StandardCategoryItemLabelGenerator("{2} %", NumberFormat.getInstance());
renderer.setItemLabelGenerator(generator);
renderer.setItemLabelsVisible(true);
renderer.setPositiveItemLabelPosition(new
ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER,
TextAnchor.CENTER, 0));
return result;
}//testBarLabelCut()
-------------------------------------
Nobody/Anonymous
None
None
Public
|
Date: 2008-01-30 15:31 Logged In: NO |
|
Date: 2007-07-24 13:38
|
|
Date: 2007-07-24 08:07
|
| Filename | Description | Download |
|---|---|---|
| screenshot.png | Example chart with bar label cut. | Download |
| screenshot.png | Left chart: without fix; right chart: with fix. | Download |
| Field | Old Value | Date | By |
|---|---|---|---|
| priority | 6 | 2008-01-30 15:32 | mhilpert |
| File Added | 238336: screenshot.png | 2007-07-24 13:38 | mhilpert |
| priority | 5 | 2007-07-24 08:08 | mhilpert |
| File Added | 238278: screenshot.png | 2007-07-24 08:07 | mhilpert |
Copyright © 2010 Geeknet, Inc. All rights reserved. Terms of Use