tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Charts > JFreeChart > XY Line Chart

XY Line Chart 

JFreeChart is a free and pure java chart library for creating professional quality charts. This requires the libraries jfreechart-1.0.13.jar and jcommon-1.0.8.jar to be in classpath. The following example shows creating a simple XY line chart.

File Name  :  
com/bethecoder/tutorials/jfree_charts/tests/XYLineChart.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.jfree_charts.tests;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class XYLineChart {

  public static void main(String arg[]) {

    // Prepare the data set
    XYSeries xySeries = new XYSeries("Number & Square Chart");
    xySeries.add(11);
    xySeries.add(24);
    xySeries.add(39);
    xySeries.add(416);
    xySeries.add(525);
    xySeries.add(636);
    XYDataset xyDataset = new XYSeriesCollection(xySeries);
    
    //Create the chart
    JFreeChart chart = ChartFactory.createXYLineChart(
        "Number & Square Chart""Number""Square", xyDataset,
        PlotOrientation.VERTICAL, true, true, false);

    //Render the frame
    ChartFrame chartFrame = new ChartFrame("XYLine Chart", chart);
    chartFrame.setVisible(true);
    chartFrame.setSize(300300);

  }
}
   

It gives the following output,
xyline.jpg


 
  


  
bl  br