JFreeChart is a comprehensive free chart library for the Java platform that enables developers to create professional-quality charts for both client-side and server-side applications with export capabilities to multiple formats including PNG and JPEG.
—
Factory methods for creating all major chart types with sensible defaults. The ChartFactory class provides static methods that handle the complex setup of plots, renderers, and datasets, allowing developers to create professional charts with minimal code.
Create pie charts for displaying categorical data as portions of a whole.
/**
* Creates a pie chart with default settings
* @param title the chart title
* @param dataset the data for the chart
* @return a pie chart
*/
public static JFreeChart createPieChart(String title, PieDataset dataset);
/**
* Creates a pie chart with full customization options
* @param title the chart title
* @param dataset the data for the chart
* @param legend flag indicating whether or not a legend is required
* @param tooltips configure chart to generate tool tips
* @param urls configure chart to generate URLs
* @return a pie chart
*/
public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls);
/**
* Creates a ring chart (donut chart) with customization options
* @param title the chart title
* @param dataset the data for the chart
* @param legend flag indicating whether or not a legend is required
* @param tooltips configure chart to generate tool tips
* @param urls configure chart to generate URLs
* @return a ring chart
*/
public static JFreeChart createRingChart(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls);
/**
* Creates multiple pie charts from category data
* @param title the chart title
* @param dataset the dataset (CategoryDataset)
* @param order the order that the data is extracted (by row or by column)
* @param legend flag indicating whether or not a legend is required
* @param tooltips configure chart to generate tool tips
* @param urls configure chart to generate URLs
* @return a chart containing multiple pie charts
*/
public static JFreeChart createMultiplePieChart(String title, CategoryDataset dataset, TableOrder order, boolean legend, boolean tooltips, boolean urls);
/**
* Creates a 3D pie chart (deprecated - use regular pie chart instead)
* @param title the chart title
* @param dataset the data for the chart
* @return a 3D pie chart
* @deprecated Use createPieChart() instead
*/
@Deprecated
public static JFreeChart createPieChart3D(String title, PieDataset dataset);Usage Examples:
import org.jfree.chart.ChartFactory;
import org.jfree.data.general.DefaultPieDataset;
// Create dataset
DefaultPieDataset<String> dataset = new DefaultPieDataset<>();
dataset.setValue("Chrome", 65.2);
dataset.setValue("Firefox", 18.7);
dataset.setValue("Safari", 9.6);
dataset.setValue("Edge", 4.8);
dataset.setValue("Other", 1.7);
// Create simple pie chart
JFreeChart chart = ChartFactory.createPieChart(
"Browser Market Share", dataset);
// Create pie chart with all options
JFreeChart chartWithOptions = ChartFactory.createPieChart(
"Browser Market Share", dataset, true, true, false);
// Create ring chart
JFreeChart ringChart = ChartFactory.createRingChart(
"Browser Market Share", dataset, true, true, false);Create bar charts for comparing categorical data with rectangular bars.
/**
* Creates a bar chart with default settings
* @param title the chart title
* @param categoryAxisLabel the label for the category axis
* @param valueAxisLabel the label for the value axis
* @param dataset the dataset for the chart
* @return a bar chart
*/
public static JFreeChart createBarChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset);
/**
* Creates a bar chart with full customization options
* @param title the chart title
* @param categoryAxisLabel the label for the category axis
* @param valueAxisLabel the label for the value axis
* @param dataset the dataset for the chart
* @param orientation the plot orientation (horizontal or vertical)
* @param legend flag indicating whether or not a legend is required
* @param tooltips configure chart to generate tool tips
* @param urls configure chart to generate URLs
* @return a bar chart
*/
public static JFreeChart createBarChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);
/**
* Creates a 3D bar chart
* @param title the chart title
* @param categoryAxisLabel the label for the category axis
* @param valueAxisLabel the label for the value axis
* @param dataset the dataset for the chart
* @param orientation the plot orientation (horizontal or vertical)
* @param legend flag indicating whether or not a legend is required
* @param tooltips configure chart to generate tool tips
* @param urls configure chart to generate URLs
* @return a 3D bar chart
*/
public static JFreeChart createBarChart3D(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);
/**
* Creates a stacked bar chart
* @param title the chart title
* @param domainAxisLabel the label for the category axis
* @param rangeAxisLabel the label for the value axis
* @param dataset the dataset for the chart
* @return a stacked bar chart
*/
public static JFreeChart createStackedBarChart(String title, String domainAxisLabel, String rangeAxisLabel, CategoryDataset dataset);
/**
* Creates a stacked bar chart with full customization options
* @param title the chart title
* @param domainAxisLabel the label for the category axis
* @param rangeAxisLabel the label for the value axis
* @param dataset the dataset for the chart
* @param orientation the plot orientation (horizontal or vertical)
* @param legend flag indicating whether or not a legend is required
* @param tooltips configure chart to generate tool tips
* @param urls configure chart to generate URLs
* @return a stacked bar chart
*/
public static JFreeChart createStackedBarChart(String title, String domainAxisLabel, String rangeAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);
/**
* Creates a waterfall chart showing cumulative effects
* @param title the chart title
* @param categoryAxisLabel the label for the category axis
* @param valueAxisLabel the label for the value axis
* @param dataset the dataset for the chart
* @param orientation the plot orientation (horizontal or vertical)
* @param legend flag indicating whether or not a legend is required
* @param tooltips configure chart to generate tool tips
* @param urls configure chart to generate URLs
* @return a waterfall chart
*/
public static JFreeChart createWaterfallChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);Usage Examples:
import org.jfree.chart.ChartFactory;
import org.jfree.data.category.DefaultCategoryDataset;
// Create dataset
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(100, "Q1", "Jan");
dataset.addValue(150, "Q1", "Feb");
dataset.addValue(120, "Q1", "Mar");
dataset.addValue(110, "Q2", "Jan");
dataset.addValue(180, "Q2", "Feb");
dataset.addValue(140, "Q2", "Mar");
// Create simple bar chart
JFreeChart chart = ChartFactory.createBarChart(
"Quarterly Sales", "Month", "Sales ($000)", dataset);
// Create horizontal bar chart
JFreeChart horizontalChart = ChartFactory.createBarChart(
"Quarterly Sales", "Month", "Sales ($000)", dataset,
PlotOrientation.HORIZONTAL, true, true, false);
// Create stacked bar chart
JFreeChart stackedChart = ChartFactory.createStackedBarChart(
"Quarterly Sales", "Month", "Sales ($000)", dataset);Create line charts for displaying trends over categories or continuous data.
/**
* Creates a line chart with default settings
* @param title the chart title
* @param categoryAxisLabel the label for the category axis
* @param valueAxisLabel the label for the value axis
* @param dataset the dataset for the chart
* @return a line chart
*/
public static JFreeChart createLineChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset);
/**
* Creates a line chart with full customization options
* @param title the chart title
* @param categoryAxisLabel the label for the category axis
* @param valueAxisLabel the label for the value axis
* @param dataset the dataset for the chart
* @param orientation the plot orientation (horizontal or vertical)
* @param legend flag indicating whether or not a legend is required
* @param tooltips configure chart to generate tool tips
* @param urls configure chart to generate URLs
* @return a line chart
*/
public static JFreeChart createLineChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);
/**
* Creates a time series chart for displaying data over time
* @param title the chart title
* @param timeAxisLabel the label for the time axis
* @param valueAxisLabel the label for the value axis
* @param dataset the dataset for the chart
* @return a time series chart
*/
public static JFreeChart createTimeSeriesChart(String title, String timeAxisLabel, String valueAxisLabel, XYDataset dataset);
/**
* Creates a time series chart with full customization options
* @param title the chart title
* @param timeAxisLabel the label for the time axis
* @param valueAxisLabel the label for the value axis
* @param dataset the dataset for the chart
* @param legend flag indicating whether or not a legend is required
* @param tooltips configure chart to generate tool tips
* @param urls configure chart to generate URLs
* @return a time series chart
*/
public static JFreeChart createTimeSeriesChart(String title, String timeAxisLabel, String valueAxisLabel, XYDataset dataset, boolean legend, boolean tooltips, boolean urls);Usage Examples:
import org.jfree.chart.ChartFactory;
import org.jfree.data.time.*;
// Create time series dataset
TimeSeries series1 = new TimeSeries("Stock Price");
series1.add(new Day(1, 1, 2023), 100.0);
series1.add(new Day(2, 1, 2023), 105.0);
series1.add(new Day(3, 1, 2023), 102.0);
series1.add(new Day(4, 1, 2023), 108.0);
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(series1);
// Create time series chart
JFreeChart chart = ChartFactory.createTimeSeriesChart(
"Stock Price History", "Date", "Price ($)", dataset);Create XY charts for displaying relationships between two continuous variables.
/**
* Creates a scatter plot
* @param title the chart title
* @param xAxisLabel the label for the X axis
* @param yAxisLabel the label for the Y axis
* @param dataset the dataset for the chart
* @return a scatter plot
*/
public static JFreeChart createScatterPlot(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset);
/**
* Creates a scatter plot with full customization options
* @param title the chart title
* @param xAxisLabel the label for the X axis
* @param yAxisLabel the label for the Y axis
* @param dataset the dataset for the chart
* @param orientation the plot orientation (horizontal or vertical)
* @param legend flag indicating whether or not a legend is required
* @param tooltips configure chart to generate tool tips
* @param urls configure chart to generate URLs
* @return a scatter plot
*/
public static JFreeChart createScatterPlot(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);
/**
* Creates an XY line chart
* @param title the chart title
* @param xAxisLabel the label for the X axis
* @param yAxisLabel the label for the Y axis
* @param dataset the dataset for the chart
* @return an XY line chart
*/
public static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset);
/**
* Creates an XY area chart
* @param title the chart title
* @param xAxisLabel the label for the X axis
* @param yAxisLabel the label for the Y axis
* @param dataset the dataset for the chart
* @return an XY area chart
*/
public static JFreeChart createXYAreaChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset);
/**
* Creates an XY bar chart
* @param title the chart title
* @param xAxisLabel the label for the X axis
* @param dateAxis flag indicating whether the X axis should be formatted as a date axis
* @param yAxisLabel the label for the Y axis
* @param dataset the dataset for the chart
* @param orientation the plot orientation (horizontal or vertical)
* @param legend flag indicating whether or not a legend is required
* @param tooltips configure chart to generate tool tips
* @param urls configure chart to generate URLs
* @return an XY bar chart
*/
public static JFreeChart createXYBarChart(String title, String xAxisLabel, boolean dateAxis, String yAxisLabel, IntervalXYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);
/**
* Creates a bubble chart for displaying three-dimensional data
* @param title the chart title
* @param xAxisLabel the label for the X axis
* @param yAxisLabel the label for the Y axis
* @param dataset the dataset for the chart (must be XYZDataset)
* @param orientation the plot orientation (horizontal or vertical)
* @param legend flag indicating whether or not a legend is required
* @param tooltips configure chart to generate tool tips
* @param urls configure chart to generate URLs
* @return a bubble chart
*/
public static JFreeChart createBubbleChart(String title, String xAxisLabel, String yAxisLabel, XYZDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);Usage Examples:
import org.jfree.chart.ChartFactory;
import org.jfree.data.xy.*;
// Create XY dataset
XYSeries series = new XYSeries("Data Points");
series.add(1.0, 2.0);
series.add(2.0, 3.5);
series.add(3.0, 2.8);
series.add(4.0, 4.1);
series.add(5.0, 3.9);
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series);
// Create scatter plot
JFreeChart scatterChart = ChartFactory.createScatterPlot(
"XY Data", "X Values", "Y Values", dataset);
// Create XY line chart
JFreeChart lineChart = ChartFactory.createXYLineChart(
"XY Data", "X Values", "Y Values", dataset);Create specialized charts for specific use cases like financial data, statistical analysis, and scientific visualization.
/**
* Creates a candlestick chart for financial data
* @param title the chart title
* @param timeAxisLabel the label for the time axis
* @param valueAxisLabel the label for the value axis
* @param dataset the dataset for the chart (must be OHLCDataset)
* @param legend flag indicating whether or not a legend is required
* @return a candlestick chart
*/
public static JFreeChart createCandlestickChart(String title, String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset, boolean legend);
/**
* Creates a high-low chart for financial data
* @param title the chart title
* @param timeAxisLabel the label for the time axis
* @param valueAxisLabel the label for the value axis
* @param dataset the dataset for the chart (must be HighLowDataset)
* @param legend flag indicating whether or not a legend is required
* @return a high-low chart
*/
public static JFreeChart createHighLowChart(String title, String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset, boolean legend);
/**
* Creates a box and whisker chart for statistical data
* @param title the chart title
* @param categoryAxisLabel the label for the category axis
* @param valueAxisLabel the label for the value axis
* @param dataset the dataset for the chart (must be BoxAndWhiskerCategoryDataset)
* @param legend flag indicating whether or not a legend is required
* @return a box and whisker chart
*/
public static JFreeChart createBoxAndWhiskerChart(String title, String categoryAxisLabel, String valueAxisLabel, BoxAndWhiskerCategoryDataset dataset, boolean legend);
/**
* Creates a box and whisker chart for time series statistical data
* @param title the chart title
* @param timeAxisLabel the label for the time axis
* @param valueAxisLabel the label for the value axis
* @param dataset the dataset for the chart (must be BoxAndWhiskerXYDataset)
* @param legend flag indicating whether or not a legend is required
* @return a box and whisker chart
*/
public static JFreeChart createBoxAndWhiskerChart(String title, String timeAxisLabel, String valueAxisLabel, BoxAndWhiskerXYDataset dataset, boolean legend);
/**
* Creates a histogram
* @param title the chart title
* @param xAxisLabel the label for the X axis
* @param yAxisLabel the label for the Y axis
* @param dataset the dataset for the chart (must be IntervalXYDataset)
* @param orientation the plot orientation (horizontal or vertical)
* @param legend flag indicating whether or not a legend is required
* @param tooltips configure chart to generate tool tips
* @param urls configure chart to generate URLs
* @return a histogram
*/
public static JFreeChart createHistogram(String title, String xAxisLabel, String yAxisLabel, IntervalXYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);
/**
* Creates a polar chart
* @param title the chart title
* @param dataset the dataset for the chart
* @param legend flag indicating whether or not a legend is required
* @param tooltips configure chart to generate tool tips
* @param urls configure chart to generate URLs
* @return a polar chart
*/
public static JFreeChart createPolarChart(String title, XYDataset dataset, boolean legend, boolean tooltips, boolean urls);
/**
* Creates a Gantt chart for project management
* @param title the chart title
* @param categoryAxisLabel the label for the category axis
* @param dateAxisLabel the label for the date axis
* @param dataset the dataset for the chart (must be IntervalCategoryDataset)
* @param legend flag indicating whether or not a legend is required
* @param tooltips configure chart to generate tool tips
* @param urls configure chart to generate URLs
* @return a Gantt chart
*/
public static JFreeChart createGanttChart(String title, String categoryAxisLabel, String dateAxisLabel, IntervalCategoryDataset dataset, boolean legend, boolean tooltips, boolean urls);
/**
* Creates a wind plot for displaying wind direction and force data
* @param title the chart title
* @param xAxisLabel the label for the X axis
* @param yAxisLabel the label for the Y axis
* @param dataset the dataset for the chart (must be WindDataset)
* @param legend flag indicating whether or not a legend is required
* @param tooltips configure chart to generate tool tips
* @param urls configure chart to generate URLs
* @return a wind plot
*/
public static JFreeChart createWindPlot(String title, String xAxisLabel, String yAxisLabel, WindDataset dataset, boolean legend, boolean tooltips, boolean urls);
/**
* Creates a wafer map chart for semiconductor wafer analysis
* @param title the chart title
* @param dataset the dataset for the chart (must be WaferMapDataset)
* @param orientation the plot orientation (horizontal or vertical)
* @param legend flag indicating whether or not a legend is required
* @param tooltips configure chart to generate tool tips
* @param urls configure chart to generate URLs
* @return a wafer map chart
*/
public static JFreeChart createWaferMapChart(String title, WaferMapDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);/**
* Gets the current chart theme used by the factory methods
* @return the chart theme
*/
public static ChartTheme getChartTheme();
/**
* Sets the chart theme to be used by the factory methods
* @param theme the new chart theme
*/
public static void setChartTheme(ChartTheme theme);Usage Example:
import org.jfree.chart.StandardChartTheme;
// Apply a custom theme to all new charts
ChartFactory.setChartTheme(new StandardChartTheme("Custom"));
// Create chart with custom theme
JFreeChart chart = ChartFactory.createBarChart(
"Sales Data", "Month", "Revenue", dataset);Install with Tessl CLI
npx tessl i tessl/maven-org-jfree--jfreechart