Pie Chart Labels

randal
2004-10-14
2013-01-13
  • randal
    randal
    2004-10-14

    I need to reformat the content of the pie chart labels so they only contain the percentage values rather than the 'category = value'.

    I've managed to improve the look and feel of the labels using:

    Color transparent = new Color( 0x00ffffff, true );
    plot.setLabelBackgroundPaint(Color.decode("#FFFFFF"));
    plot.setLabelFont(new Font("Arial", Font.PLAIN, 8));
    plot.setLabelLinkMargin(0);
    plot.setLabelShadowPaint(transparent);
    plot.setLabelOutlinePaint(transparent);

    ...which almost stops the pie from being crushed horizontally but I'd like to reformat the text too.

    Any ideas?

    Thanks,
    Randal.

     
    • randal
      randal
      2004-10-20

      Ok, thanks to Brian post in the help forum I've taken a look at the JFreeChart forum and found the answer.  ;)

      StandardPieItemLabelGenerator spilg = new StandardPieItemLabelGenerator("{2}");
      plot.setLabelGenerator(spilg);

      {2} is the percentage (calculated for you).  You can also use {0} (the category name) and {1} (the categorys value), and put them in any combination ("{0} = {1}" is the default).

      Randal.

       
    • ziggy
      ziggy
      2004-11-10

      This is a great solution to customizable pie chart label, but I'm having a few problems implementing it in our system.  The package that StandardPieItemLabelGenerator , org.jfree.chart.labels, is not found by my system even though I have Cewolf working in my application.  I'm using Cewolf version 0.9.8 with JFreeChart 0.9.8 (which I think is fairly old).  The way I understand it is that Cewolf is only designed to work with the version of JFreeChart it is delivered with (0.9.8).

      I'm wondering if this is a JFreeChart version issue.  Is the StandardPieItemLabelGenerator a fairly new class?   Is there a newer version of Cewolf that uses a newer version of JFreeChart.  Should I simply recompile the Cewolf source with a new version of JFreeChart?

      Thanks,

      Ziggy