DOWNLOAD PDF,Examples
//1.pie chart
import java.awt.*;
import org.jfree.chart.*;
import org.jfree.chart.title.*;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.ui.*;
public class pie{
public static void main(String arg[]){
DefaultPieDataset pieDataset = new DefaultPieDataset();
pieDataset.setValue("One", new Integer(10));
pieDataset.setValue("Two", new Integer(20));
pieDataset.setValue("Three", new Integer(30));
pieDataset.setValue("Four", new Integer(10));
pieDataset.setValue("Five", new Integer(20));
pieDataset.setValue("Six", new Integer(10));
JFreeChart chart = ChartFactory.createPieChart
("Pie Chart using JFreeChart", pieDataset, true,true,true);
ChartFrame frame1=new ChartFrame("Pie Chart",chart);
frame1.setVisible(true);
frame1.setSize(300,300);
}
}
//2.3dpie chart
import java.awt.*;
import org.jfree.chart.*;
import org.jfree.chart.title.*;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.ui.*;
import org.jfree.chart.plot.*;
import org.jfree.util.*;
public class Pie3D{
public static void main(String arg[]){
DefaultPieDataset pieDataset = new DefaultPieDataset();
pieDataset.setValue("One", new Integer(10));
pieDataset.setValue("Two", new Integer(20));
pieDataset.setValue("Three", new Integer(30));
pieDataset.setValue("Four", new Integer(10));
pieDataset.setValue("Five", new Integer(20));
pieDataset.setValue("Six", new Integer(10));
JFreeChart chart = ChartFactory.createPieChart3D
("3D Pie Chart", pieDataset, true,true,true);
PiePlot3D p=(PiePlot3D)chart.getPlot();
p.setForegroundAlpha(0.5f);
ChartFrame frame1=new ChartFrame("3D Pie Chart",chart);
frame1.setVisible(true);
frame1.setSize(300,300);
}
}
//3.Area Chart Example
import java.awt.*;
import java.io.*;
import org.jfree.chart.*;
import org.jfree.data.category.*;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.*;
import org.jfree.chart.renderer.category.*;
import org.jfree.chart.plot.*;
public class Area{
public static void main(String arg[]){
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(4.0, "Science", "Rahul");
dataset.addValue(3.0, "Maths", "Rahul");
dataset.addValue(5.0, "Science", "Vinod");
dataset.addValue(2.0,"Maths", "Vinod");
dataset.addValue(3.0, "Science", "Prashant");
dataset.addValue(5.0, "Maths", "Prashant");
dataset.addValue(6.0, "Science", "Tapan");
dataset.addValue(2.0, "Maths", "Tapan");
dataset.addValue(3.0,"Science", "Santosh");
dataset.addValue(5.0, "Maths", "Santosh");
JFreeChart chart = ChartFactory.createAreaChart
("Comparison between Students Marks","Students", "Marks ",
dataset, PlotOrientation.VERTICAL, true,true, false);
chart.setBackgroundPaint(Color.yellow);
chart.getTitle().setPaint(Color.blue);
CategoryPlot p = chart.getCategoryPlot();
p.setForegroundAlpha(0.7f);
p.setRangeGridlinePaint(Color.red);
p.setDomainGridlinesVisible(true);
p.setDomainGridlinePaint(Color.black);
CategoryItemRenderer renderer = p.getRenderer();
renderer.setSeriesPaint(1, Color.red);
renderer.setSeriesPaint(0, Color.green);
ChartFrame frame1=new ChartFrame("Area Chart",chart);
frame1.setVisible(true);
frame1.setSize(300,300);
}
}
//XYArea Chart Example
import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.*;
import org.jfree.data.*;
public class xyArea{
public static void main(String arg[]){
XYSeries series = new XYSeries("Average Weight");
series.add(20.0, 20.0);
series.add(40.0, 25.0);
series.add(55.0, 50.0);
series.add(70.0, 65.0);
XYDataset xyDataset = new XYSeriesCollection(series);
JFreeChart chart = ChartFactory.createXYAreaChart
("XY Chart using JFreeChart", "Age", "Weight",
xyDataset, PlotOrientation.VERTICAL, true,
true, false);
ChartFrame frame1=new ChartFrame("XYArea Chart",chart);
frame1.setVisible(true);
frame1.setSize(300,300);
}
}
5//XYLine Chart Example
import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.*;
import org.jfree.data.*;
public class xyLine{
public static void main(String arg[]){
XYSeries series = new XYSeries("Average Weight");
series.add(20.0, 20.0);
series.add(40.0, 25.0);
series.add(55.0, 50.0);
series.add(70.0, 65.0);
XYDataset xyDataset = new XYSeriesCollection(series);
JFreeChart chart = ChartFactory.createXYLineChart
("XYLine Chart using JFreeChart", "Age", "Weight",
xyDataset, PlotOrientation.VERTICAL, true, true, false);
ChartFrame frame1=new ChartFrame("XYLine Chart",chart);
frame1.setVisible(true);
frame1.setSize(300,300);
}
}
6//Bar Chart Example
import org.jfree.chart.*;
import org.jfree.data.category.*;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.*;
import org.jfree.data.*;
import org.jfree.chart.renderer.category.*;
import org.jfree.chart.plot.*;
import java.awt.*;
public class BarExample1{
public static void main(String arg[]){
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.setValue(2, "Marks", "Rahul");
dataset.setValue(7, "Marks", "Vinod");
dataset.setValue(4, "Marks", "Deepak");
dataset.setValue(9, "Marks", "Prashant");
dataset.setValue(6, "Marks", "Chandan");
JFreeChart chart = ChartFactory.createBarChart
("BarChart using JFreeChart","Student", "Marks", dataset,
PlotOrientation.VERTICAL, false,true, false);
chart.setBackgroundPaint(Color.yellow);
chart.getTitle().setPaint(Color.blue);
CategoryPlot p = chart.getCategoryPlot();
p.setRangeGridlinePaint(Color.red);
ChartFrame frame1=new ChartFrame("Bar Chart",chart);
frame1.setVisible(true);
frame1.setSize(400,350);
}
}
7//3D Bar Chart Example
import org.jfree.chart.*;
import org.jfree.data.category.*;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.*;
import org.jfree.data.*;
import org.jfree.chart.renderer.category.*;
import org.jfree.chart.plot.*;
import java.awt.*;
public class BarExample2{
public static void main(String arg[]){
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.setValue(6, "Science", "Rahul");
dataset.setValue(8, "Maths", "Rahul");
dataset.setValue(5, "Science", "Deepak");
dataset.setValue(3, "Maths", "Deepak");
dataset.setValue(6, "Science", "Vinod");
dataset.setValue(9, "Maths", "Vinod");
dataset.setValue(2, "Science", "Chandan");
dataset.setValue(4, "Maths", "Chandan");
JFreeChart chart = ChartFactory.createBarChart3D
("Comparison between Students","Students", "Marks",
dataset, PlotOrientation.VERTICAL, true,true, false);
chart.setBackgroundPaint(Color.yellow);
chart.getTitle().setPaint(Color.blue);
CategoryPlot p = chart.getCategoryPlot();
p.setRangeGridlinePaint(Color.red);
ChartFrame frame1=new ChartFrame("3D Bar Chart",chart);
frame1.setVisible(true);
frame1.setSize(300,300);
}
}
8//WaterFall Chart Example
import java.awt.*;
import org.jfree.chart.*;
import org.jfree.data.category.*;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.*;
import org.jfree.data.*;
import org.jfree.chart.renderer.category.*;
import org.jfree.chart.plot.*;
public class Waterfall{
public static void main(String arg[]){
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(3.0, "Salary", "Rahul");
dataset.addValue(3.0, "Salary", "Prashant");
dataset.addValue(2.0, "Salary", "Chandan");
dataset.addValue(2.0, "Salary", "Vinod");
dataset.addValue(10.0, "Salary", "Total");
JFreeChart chart = ChartFactory.createWaterfallChart
("Comparison between Employees","Employee", "Salary",
dataset, PlotOrientation.VERTICAL, true,true, false);
chart.getTitle().setPaint(Color.blue);
CategoryPlot p = chart.getCategoryPlot();
p.setRangeGridlinePaint(Color.red);
p.setDomainGridlinesVisible(true);
p.setDomainGridlinePaint(Color.black);
ChartFrame frame1=new ChartFrame("WaterFall Chart",chart);
frame1.setVisible(true);
frame1.setSize(400,350);
}
}
9//Polar Chart Example
10//Bar Chart Example using JFreeChart
11//Horizontal Bar Chart Example using JFreeChart
12//Stacked 3d Bar Chart Example using JFreeChart
13//Stacked Bar Chart using JFreeChart
14//Stacked Bar Chart Example using JFreeChart