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
PieChart section labels in currency
Re: PieChart section labels in currency
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.
> 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.
Re: PieChart section labels in currency
Great! I used the below code and it worked like a champ.
PiePlot pie = (PiePlot)chart.getPlot();
pie.setValueFormatString("$#,###,##0.00;");
Thanks DG!
PiePlot pie = (PiePlot)chart.getPlot();
pie.setValueFormatString("$#,###,##0.00;");
Thanks DG!