JFreeChart XY Step Area Chart

Chapter: JFreeChart Last Updated: 10-06-2017 03:50:15 UTC

Program:

            /* ............... START ............... */
                
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;

public class JavaJFreeChartXYStepAreaChart extends JFrame{
	
	private static final long serialVersionUID = 1L;

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

	   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
	      dataset.addSeries(series1);
	      dataset.addSeries(series2);
	      return dataset;
	   }

	   public static void main(String[] args) {
	      SwingUtilities.invokeLater(() -> {
	    	  JavaJFreeChartXYStepAreaChart example = new JavaJFreeChartXYStepAreaChart("XY Step Area Chart");
	         example.setSize(800, 400);
	         example.setLocationRelativeTo(null);
	         example.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
	         example.setVisible(true);
	      });
	   }
}
                /* ............... END ............... */
        

Output


JFreeChart XY Step Area Chart

Tags

JFreeChart XY Step Area Chart, Java, JFreeChart

Similar Programs Chapter Last Updated
JFreeChart Scatter Chart JFreeChart 20-10-2017
JFreeChart XY Step Chart JFreeChart 10-06-2017
JFreeChart Wafer Map Chart JFreeChart 10-06-2017
JFreeChart BarChart Color Customise JFreeChart 14-10-2016
JFreeChart Bar Chart 3D Example JFreeChart 05-08-2016
JFreeChart Bar Chart 3D Horizontal JFreeChart 05-08-2016
JFreeChart Area Chart Example JFreeChart 05-08-2016
JFreeChart Bubble Chart Example JFreeChart 03-08-2016
JFreeChart XY Chart Example JFreeChart 03-08-2016
JFreeChart Dynamic Data Demo Chart Example JFreeChart 08-07-2016
JFreeChart Background Paint Example JFreeChart 07-07-2016
JFreeChart Get Plot Example JFreeChart 07-07-2016
JFreeChart Background Color Example JFreeChart 06-07-2016
JFreeChart Subtitles Example JFreeChart 06-07-2016
JFreeChart Chart Title Example JFreeChart 06-07-2016
JFreeChart Chart Border Example JFreeChart 05-07-2016
JFreeChart Time Series Chart Example JFreeChart 23-06-2016
JFreeChart Pie Chart 3D Example JFreeChart 08-06-2016
JFreeChart Line Chart Example JFreeChart 04-06-2016
JFreeChart Bar Chart Example JFreeChart 22-09-2018
JFreeChart Pie Chart Example JFreeChart 04-06-2016

1