Dashboard Discussion, Support, Examples, Help » How-To

Decimal place in PIE chart Item labels

(4 posts)
  1. Hi I am displaying percentages in item lables of a PIE chart and it is rounding up. I actually want to be able to display the item lable percentage in 2 decimal places. Can you please advise how to do this? Many Thanks

    Posted 8 months ago #
  2. Additionally I am using the following code:

    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}{0}"));

    I believe there is additional code that can be appended to the above 'new DecimalFormat("0.00%")) but this doesn't seem to work.

    Posted 8 months ago #
  3. Tom,
    Please try the below code in the java script. NOTE: There are two new import statements import java.text.numberformat and ..decimalformat.

    //-----------
    //import the necessary classes
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.plot.PiePlot;
    import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
    import java.text.NumberFormat;
    import java.text.DecimalFormat;

    plot =((PiePlot) chart.getPlot());
    plot.setForegroundAlpha(0.5f);

    //chart.setBackgroundPaint(new GradientPaint(0,0,Color.gray.brighter().brighter(),0,displayFrame.getHeight(), Color.LIGHT_GRAY));

    float h = displayFrame.getHeight();
    float w = displayFrame.getWidth();
    GradientPaint gradientPaint = new GradientPaint(0.0F, 10.0F, Color.white, 0, h, Color.orange);
    // plot.setBackgroundPaint(gradientPaint);
    chart.getTitle().setPaint(Color.blue);

    plot.setLabelGenerator(

    new StandardPieSectionLabelGenerator(
    "{0}={2}",
    new DecimalFormat("#,##0"),
    new DecimalFormat("0.0%"))
    );

    //-----------

    Posted 8 months ago #
  4. Thank You this worked

    Posted 8 months ago #

RSS feed for this topic

Reply

You must log in to post.