JFreeChart – Java chart library

JFreeChart is the most widely used chart library for Java, By using JFreeChart library that makes it easy for developers to display professional quality charts in their applications.

JFreeChart is a free 100% Java chart library that makes it easy for developers to display professional quality charts in their applications

JFreeChart’s extensive feature set includes:

  • Consistent and well-documented API, supporting a wide range of chart types;
  • Flexible design that is easy to extend, and targets both server-side and client-side applications;
  • Support for many output types, including Swing components, image files (including PNG and JPEG), and vector graphics file formats (including PDF, EPS and SVG); JFreeChart is “open source” or, more specifically, free software. It is distributed under the terms of the GNU Lesser General Public Licence (LGPL), which permits use in proprietary applications.

It supports following type of charts

  • X-Y charts (line, spline and scatter). Time axis is possible.
  • Pie charts
  • Gantt charts
  • Bar charts (horizontal and vertical, stacked and independent). It also has built-in histogram plotting.
  • Single valued (thermometer, compass, speedometer) that can then be placed over map.
  • Various specific charts (wind chart, polar chart, bubbles of varying size, etc).

JFreeChart Example


import javax.swing.JFrame;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.util.Rotation;


public class JFreeChartExample extends JFrame {

private static final long serialVersionUID = 1L;

public JFreeChartExample(String applicationTitle, String chartTitle) {
super(applicationTitle);
//Creates a sample dataset
DefaultPieDataset dataSet = new DefaultPieDataset();
dataSet.setValue("Chrome", 29);
dataSet.setValue("InternetExplorer", 36);
dataSet.setValue("Firefox", 35);

// based on the dataset we create the chart
JFreeChart pieChart = ChartFactory.createPieChart3D(chartTitle, dataSet, true, true, false);
PiePlot plot = (PiePlot) pieChart.getPlot();
plot.setStartAngle(290);
plot.setDirection(Rotation.CLOCKWISE);
plot.setForegroundAlpha(0.5f);

// Adding chart into a chart panel
ChartPanel chartPanel = new ChartPanel(pieChart);

// settind default size
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

// add to contentPane
setContentPane(chartPanel);
}
public static void main(String[] args) {
JFreeChartExample chart = new JFreeChartExample("Browser Usage Statistics", "Which Browser are you using?");
chart.pack();
chart.setVisible(true);
}
}

OUTPUT :

Hope you will like this. Cheers… 🙂