I want to know if we can change color of the label values on the bar charts. Not the x axis and Y axis labels but the actual value displaying on the bar.
Thanks in advance for all help.
Thank You Sanda.
In fact, I am talking about Item label color.
I tried the option you mentioned even before posting. Somehow , the changes I applied seem to occur on pie charts but not bar charts. Do we have any restriction for bar charts.
General Item label color was black Initially. My background color is dark and hence , I am uanle to see the actual label being printed on bar. I wanted to change to white which did not work on bar graph. I clicked thr Item Label on Bar3D plot properties on Ireport and changed the color to white. It did not work.
If I change my color to white, what would my background color be?Can it be white? Does that background color has any significance since on bar chart it usually is taken up by series color? Am I making sense...:)
Hi, Bar3D charts need an additional setting for item label positions. This setting can be customized in a chart customizer: CategoryPlot categoryPlot = (CategoryPlot)jfreeChart.getPlot(); categoryPlot.getRenderer().setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER)); Hope this helps, sanda
I think I am getting some where here.
Initially, i thought the code you gave did not work. Now it works. I tried to use same Customizer class for 2 charts, one which was telling maximum category label lines and the other label color. Can I not use same customizer for both? If I want both features to be applied for all charts of same type?
Also, what are these Anchor positions? My ItemLabel comes in white now, but outside the stacked bar range. I tried to Center/Inside12 as opposed to Outside12. It did not work. Please help.
CategoryPlot cplot = chart.getCategoryPlot(); cplot.getRenderer().setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BOTTOM_CENTER)); cplot.getRenderer().setBaseItemLabelPaint(Color.WHITE);</td></tr></tbody></table>
Hi, Let's see if all needed elements are put together in your report:
- The isShowLabels attribute in the bar3DPlot element has to be set to true (it's false by default): <bar3DPlot isShowLabels="true">.
- The itemLabel in the bar3DPlot element has to be set too: <itemLabel color="#FFFFFF" backgroundColor="#000000"/>
- Label positions have to be set in a chart customizer, like already discussed
CategoryPlot categoryPlot = (CategoryPlot)jfreeChart.getPlot(); categoryPlot.getRenderer().setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER)); If all these settings don't work together as expected, then please post the jrxml sample here, maybe some other clues could be found within. Hope this helps, sanda
PS: Sorry, I wrote my answer at the same time with your previous one, and didn't know meanwhile it started to work.
If both charts are the same type (ie Bar3D), then the same customizer applied to them will set the same properties for both charts. If you need different settings for each chart, then different chart customizer classes are required.
If charts are different types (ie Bar and Bar3D), one can distinguish between them - using the class name, or the instanceof operator - and different settings can be applied for each chart apart.
These anchors are used internally by the JFreeChart engine in order to render labels at some predefined positions. They represent positions an item label can take, relative to a given bar in the CategoryPlot, and the relative text position within the label rectangle. Test them and choose the most appropriate for your needs.
Post Edited by shertage at 03/07/2011 15:57
Hi, But how about this one? categoryPlot.getRenderer().setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, Math.PI/2)); Regarding the chart customizers role in JasperReports, I have to point out that is very important to distinguish between JasperReports and JFreeChart libraries, because they are not the same. JFreeChart is a third party library, and chart customizers just pass the chart configuration responsibility to the JFreeChart engine itself. So, when someone uses a chart customizer, it's supposed that he or she is able to work directly with JFreeChart APIs. If you really need advanced chart configuration, like the above one, then you have to search the appropriate JFreeChart classes and methods on your own. JasperReports is a reporting engine, it is not dedicated to chart generation. When rendering charts it uses the most common and the most frequent required chart settings available in JFreeChart. All other possible settings can be done using the customizer, and properly knowing the JFreeChart APIs. And here is no more JasperReports' area, here is only you facing the JFreeChart APIs. :) This is why, if the last solution I suggested above doesn't work, I would encourage you to 'dig' into JFreeChart by yourself, and become familiarized with these APIs. Your own solution should be the most appropriate one. Hope this helps and have a nice day, sanda