Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package chart; /** * * @author admin */ import javax.swing.JPanel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; public class PieChart_AWT extends ApplicationFrame { public PieChart_AWT(String title) { super(title); setContentPane(createDemoPanel()); } private static PieDataset createDataset() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("IPhone 5s", new Double(20)); dataset.setValue("SamSung Grand", new Double(20)); dataset.setValue("MotoG", new Double(40)); dataset.setValue("Nokia Lumia", new Double(10)); return dataset; } private static JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart("Mobile Sales", // chart title dataset, // data true, // include legend true, false); return chart; } public static JPanel createDemoPanel() { JFreeChart chart = createChart(createDataset()); return new ChartPanel(chart); } public static void main(String[] args) { PieChart_AWT demo = new PieChart_AWT("Mobile Sales"); demo.setSize(560, 367); RefineryUtilities.centerFrameOnScreen(demo); demo.setVisible(true); } }