Sunday, 7 June 2015

JFreeChart Multiple Pie charts

Multiple Pie charts enable you, to display number of pie charts in a single chart. ChartFactory class provides following constructors to instantiate MultiplePieChart.

public static JFreeChart createMultiplePieChart(String title, CategoryDataset dataset, TableOrder order, boolean legend, boolean tooltips, boolean urls)

public static JFreeChart createMultiplePieChart3D(String title, CategoryDataset dataset, TableOrder order, boolean legend, boolean tooltips, boolean urls)

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.util.TableOrder;

public class Main {
 public static void main(String args[]) {

  String title = "Multiple Pie chart demo";
  boolean legend = true;
  boolean tooltips = true;
  boolean urls = true;

  double sales[][] = { { 125.3, 34.8, 98.76, 350.34 },
    { 115.3, 54.8, 93.76, 390.34 },
    { 135.3, 64.8, 108.76, 391.34 }, { 125.9, 34.3, 98.77, 351 },
    { 185.3, 134.8, 298.76, 450.34 } };

  CategoryDataset dataset = DatasetUtilities.createCategoryDataset(
    "Region ", "Sales/Q", sales);

  /* create chart */
  JFreeChart chart = ChartFactory.createMultiplePieChart(title, dataset,
    TableOrder.BY_ROW, legend, tooltips, urls);

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

 }
}


Output



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment