PieChart section labels in currency

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Bray Jones

PieChart section labels in currency

Post by Bray Jones » Thu Apr 18, 2002 8:48 pm

Just started using JFreeChart. Awesome product!

Question:

I use "pie.setSectionLabelType(PiePlot.VALUE_LABELS)" to display values in my piechart.

The values are doubles which come out on the graph beside each section labeled (ie. 4300.15). I want to display this value in currency style (ie. $4,300.15) in the section label.

Can I do this? If so, how?

Thanks for any help or suggestions.

Bray Jones

David Gilbert

Re: PieChart section labels in currency

Post by David Gilbert » Fri Apr 19, 2002 9:28 am

Bray Jones wrote:
> I use "pie.setSectionLabelType(PiePlot.VALUE_LABELS)" to
> display values in my piechart.
>
> The values are doubles which come out on the graph beside
> each section labeled (ie. 4300.15). I want to display this
> value in currency style (ie. $4,300.15) in the section label.
>
> Can I do this? If so, how?

You can set the format using:

public void setValueFormatString(String format)
in the PiePlot class. This just creates a new DecimalFormat object using the supplied format. I'm pretty sure that DecimalFormat will allow you to include the currency symbol in the format.

Regards,

DG.

Bray Jones

Re: PieChart section labels in currency

Post by Bray Jones » Fri Apr 19, 2002 1:28 pm

Great! I used the below code and it worked like a champ.

PiePlot pie = (PiePlot)chart.getPlot();
pie.setValueFormatString("$#,###,##0.00;");

Thanks DG!

Locked