values on top of bars in barchart ? possible ?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
prakash.parvath
Posts: 3
Joined: Sat May 09, 2009 10:02 am

values on top of bars in barchart ? possible ?

Post by prakash.parvath » Tue May 12, 2009 6:55 am

Hi
i just want to know is it possible to display values (as labels) on top of every bar in a bar chart like below
Image

please let me know, as its a mandatory requirement for me.

~Prakash

prakash.parvath
Posts: 3
Joined: Sat May 09, 2009 10:02 am

Re: values on top of bars in barchart ? possible ?

Post by prakash.parvath » Tue May 12, 2009 7:54 am

thanks i got it using :

Code: Select all

renderer.setSeriesItemLabelGenerator(0, 
                                                       new StandardCategoryItemLabelGenerator("        {2}",NumberFormat.getCurrencyInstance(Locale.US))); 
				
renderer.setSeriesItemLabelsVisible(0, true);
~Prakash

ranyeng
Posts: 13
Joined: Fri May 22, 2009 6:53 am

Re: values on top of bars in barchart ? possible ?

Post by ranyeng » Tue May 26, 2009 7:43 am

Hi,

I am also facing the same problem. I cant display values at corresponding columns.... Following is part of my code


final JFreeChart chart = ChartFactory.createBarChart(
"Bar Chart Demo 3", // chart title
"Category", // domain axis label
"Value", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // the plot orientation
false, // include legend
true,
false
);

chart.setBackgroundPaint(Color.lightGray);

// get a reference to the plot for further customisation...
final CategoryPlot plot = chart.getCategoryPlot();


final CategoryItemRenderer renderer = new CustomRenderer(
new Paint[] {Color.red, Color.blue, Color.green,
Color.yellow, Color.orange, Color.cyan,
Color.magenta, Color.blue}
);


renderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator("{2}",NumberFormat.getCurrencyInstance(Locale.US)));

renderer.setSeriesItemLabelsVisible(0, true);


Please help me...

Thanks,
Ranjan

ranyeng
Posts: 13
Joined: Fri May 22, 2009 6:53 am

Re: values on top of bars in barchart ? possible ?

Post by ranyeng » Tue May 26, 2009 10:54 am

I got it.... I forget adding


chart.getCategoryPlot().setRenderer(renderer);

Locked