Sunday, 7 June 2015

JFreeChart 3D Pie charts

ChartFactory class provides following constructors, to create 3D Pie charts.

public static JFreeChart createPieChart3D(String title, PieDataset dataset)
public static JFreeChart createPieChart3D(String title, PieDataset dataset, boolean legend, boolean tooltips, Locale locale)

public static JFreeChart createPieChart3D(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls)

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.util.Rotation;

public class Main {
 public static void main(String args[]) {
  /* Create dataset */
  DefaultPieDataset dataset = new DefaultPieDataset();
  dataset.setValue("2004-2005", 58);
  dataset.setValue("2005-2006", 41);
  dataset.setValue("2006-2007", 85.3);
  dataset.setValue("2007-2008", 81);

  /* create chart */
  JFreeChart chart = ChartFactory.createPieChart3D("Simple Piechart",
    dataset);

  /* Get PiePlot object */
  PiePlot3D plot = (PiePlot3D) chart.getPlot();

  /* Set custom labels for section */
  plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})"));

  plot.setDarkerSides(true);
  plot.setStartAngle(290D);
  plot.setDirection(Rotation.CLOCKWISE);
  plot.setForegroundAlpha(0.5F);
  plot.setNoDataMessage("No data to display");

  /* create and display chart on frame */
  ChartFrame frame = new ChartFrame("JFreeChart Demo", chart);
  frame.pack();
  frame.setVisible(true);

 }
}


Output



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment