tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Charts > JFreeChart > Save Chart As JPEG

Save Chart As JPEG 

JFreeChart is a free and pure java chart library for creating professional quality charts. This requires the libraries jfreechart-1.0.13.jar and jcommon-1.0.8.jar to be in classpath. The following example shows exporting a simple 3D pie chart as JPEG.

File Name  :  
com/bethecoder/tutorials/jfree_charts/tests/ChartAsJPEG.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.jfree_charts.tests;

import java.io.File;
import java.io.IOException;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;

public class ChartAsJPEG {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {
    
    //Prepare the data set
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    pieDataset.setValue("Coca-Cola"26);
    pieDataset.setValue("Pepsi"20);
    pieDataset.setValue("Gold Spot"12);
    pieDataset.setValue("Slice"14);
    pieDataset.setValue("Appy Fizz"18);
    pieDataset.setValue("Limca"10);
    
    //Create the chart
    JFreeChart chart = ChartFactory.createPieChart3D(
        "Soft Dink 3D Pie Chart", pieDataset, true, true, true);
    
    //Save chart as JPEG
      ChartUtilities.saveChartAsJPEG(new File("soft3d.jpg"), chart, 400300);
  }

}
   

It gives the following output,

soft3d.jpg


 
  


  
bl  br