JFreeChart - XY Step Area Chart example

Posted on February 21, 2017

A XY Step Area Chart is much like XY step line chart except that the area under them is shaded. The Step Area Charts can be used to highlight the increase or decrease in values over time.

In this post, we will show you how to create a XY Step Area Chart using the JFreeChart 1.0.19 library.

The following example demonstrates how to create a simple XY Step Area Chart using the JFreeChart.


package com.boraji.tutorial.jfreechart;

import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

 * @author imssbora
public class XYStepAreaChartExample extends JFrame {

   private static final long serialVersionUID = 1L;

   public XYStepAreaChartExample(String title) {
      // Create dataset
      XYDataset dataset = createDataset();
      // Create chart
      JFreeChart chart = ChartFactory.createXYStepAreaChart(
            "XY Step Area Chart | WWW.BORAJI.COM", // Chart Title
            "X-Axis", // X-Axis Label
            "Y-Axis", // Y-Axis Label
      XYPlot plot=(XYPlot)chart.getPlot();
      plot.setBackgroundPaint(new Color(229, 150, 97, 60));
      ChartPanel panel = new ChartPanel(chart);

   private XYDataset createDataset() {
      XYSeriesCollection dataset = new XYSeriesCollection();

      XYSeries series1 = new XYSeries("Series1");
      series1.add(2, 4);
      series1.add(3, 6);
      series1.add(5, 2);
      series1.add(8, 5);
      series1.add(1, 8);
      XYSeries series2 = new XYSeries("Series2");
      series2.add(5, 6);
      series2.add(9, 5);
      series2.add(10, 9);
      series2.add(18, 11);
      series2.add(15, 18);
      // Add series to dataset
      return dataset;

   public static void main(String[] args) {
      SwingUtilities.invokeLater(() -> {
         XYStepAreaChartExample example = new XYStepAreaChartExample("XY Step Area Chart");
         example.setSize(800, 400);