Generating PieChart using JFreeChart (using plot)

I have already posted one snippet to generate a PieChart using JFreeChart. This code snippet make use of “pie plot” to generate the chart.

static void drawPieChartUsingPlot() 
{ 
 System.out.print("Creating the chart using plot "); 
 DefaultPieDataset pieDataset = new DefaultPieDataset(); 
 pieDataset.setValue("Subin", new Integer(70)); 
 pieDataset.setValue("Sachin", new Integer(33)); 
 pieDataset.setValue("Salman", new Integer(43)); 
 pieDataset.setValue("SRK", new Integer(6));
 PiePlot plot = new PiePlot(pieDataset); 
 JFreeChart chart = new JFreeChart("Sample Pie-chart using Plot", plot);
 try 
 { 
    File image = new File("MyChart.png"); 
    ChartUtilities.saveChartAsPNG(image, chart, 500, 300); 
    System.out.println("[done]");  

 } 
 catch (java.io.IOException exc) 
 { 
    System.err.println("Error writing image to file"); 
 } 
}
Advertisements