A discussion forum for JFreeChart (a 2D chart library for the Java platform).
-
hl_107
- Posts: 5
- Joined: Wed Mar 10, 2010 8:28 pm
- antibot: No, of course not.
Post
by hl_107 » Wed Mar 10, 2010 11:16 pm
I am using 1.0.13. Barchart works fine with positive values, but the alignment seems to be off with negative values. Below is a screenshot. setBaseNegativeItemLabelPosition doesn't seem to help either.
Can someone pls help me out here?
thanks
Jeff
Code: Select all
JFreeChart chart = ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, false, true, false);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
BarRenderer renderer = (BarRenderer) plot.getRenderer();
ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER);
renderer.setBasePositiveItemLabelPosition(p);
renderer.setBaseNegativeItemLabelPosition(p);
if (barColor != null && barColor.length > 0) {
int i = 0;
for (Color c : barColor) {
renderer.setSeriesPaint(i++, c);
renderer.setShadowVisible(false);
}
}

-
paradoxoff
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Post
by paradoxoff » Thu Mar 11, 2010 10:25 pm
Apparently, you have two series in your dataset, and the BarRenderer thus reserves space for two bars in every category. The bad thing is that no category has values for both series. BAC, AAPL and INTC have only values for the first series (which is shown in green), and FXI has only a value for the second series (which is shown in red).
The fact that the single value for the second series of the FXI category is negative has nothing to do with the problem.
Just create a dataset with one series, and change the renderer to colorize the bar for the series with a negative value in a special way (see the FAQ for suggestions).