Hi everyone,
I have a servlet, which creates two separate horizontal bar charts using ChartFactory. The first chart is stacked and has several series. The second chart is not stacked and has only one series. I tried to make value labels visible in the charts, but have problems.
In the stacked chart, the values don't show up at all, no matter what I do. In the non-stacked, the values are shown above each bar (although the bars are horizontal) and hence the value of each bar is partially hidden behind the bar above it. Especially in the stacked case I would like the values to be displayed ON the bars.
Here's what I have tried:
CategoryPlot plot = chart.getCategoryPlot();
// First tried only the following line
plot.setLabelsVisible(true);
// Then tried adding the following two
Font labelFont = new Font("Helvetica", Font.PLAIN, 10);
plot.setLabelFont(labelFont);
// The following line does not have any effect either
plot.setVerticalLabels(true);
// To make sure that the text is not white as is the background.
plot.setLabelPaint(Color.black);
My servlet does the above before calling ChartUtilities.writeChartAsPNG.
I'm running JDK 1.4 and Tomcat 4.1 on Windows 2000.
Can anyone help? Am I doing something wrong?
Thank you.
Timo
Problems with value labels in horizontal bar charts
Re: Problems with value labels in horizontal bar charts
Hi Timo,
There are a few things that get added to JFreeChart in an incomplete state, and the value labels for bar charts is one of them. It works well (I think) for vertical bar charts, but not necessarily other chart types. The code that needs looking at is in the drawCategoryItem method of each CategoryItemRenderer, but I won't have a chance to work on this for a while...hopefully someone else will.
Regards,
DG.
There are a few things that get added to JFreeChart in an incomplete state, and the value labels for bar charts is one of them. It works well (I think) for vertical bar charts, but not necessarily other chart types. The code that needs looking at is in the drawCategoryItem method of each CategoryItemRenderer, but I won't have a chance to work on this for a while...hopefully someone else will.
Regards,
DG.