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”);
 }
}

2 Responses to “Generating PieChart using JFreeChart (using plot)”

  1. Great example.

    Can you show an example of changing the color of the pie chart?

  2. Hi,

    I have posted a code snippet to generate a Pie Chart with custom colors. Please find it here: http://javabeanz.wordpress.com/2007/08/06/creating-pie-charts-using-custom-colors-jfreechart/

    Subin

Leave a Reply

You must be logged in to post a comment.