Home Chartgraphs XYLine Chart
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

XYLine Chart

Advertisement
In this section we are providing you an example to create a XYLine Chart.

XYLine Chart

     

In this section we are providing you an example to create a XYLine Chart.

Description of Program
  
For creating a XYLine Chart we have to define a set of x,y coordinates by using an object of XYSeries class. Then we add the data in this object that will show in our XYLine chart. After adding the data we make the object of XYDataset of XYSeriesCollection type and add XYSeries object in the dataset. 

Description of Code
  
  XYSeries series = new XYSeries("Average Weight");
For defining a set of x,y coordinates we use an object of XYSeries class.
  
Then we add the data in the XYSeries object by invoking add() method.
  series.add(20.0, 50.0);

    XYDataset xyDataset = new XYSeriesCollection(series);
Now we have to create the object of XYDataset type of XYSeriesCollection and add the XYSeries object in the dataset.

    JFreeChart chart = ChartFactory.createXYLineChart("XYLine Chart using JFreeChart", "Age", "Weight", xyDataset, PlotOrientation.VERTICAL, true, true, false);
After creating the dataset we create the XYLine Chart by invoking the createXYLineChart() method. This method is a static method of ChartFactory class and its returns the object of JFreeChart type.This method syntax is:
  
Public static JFreeChart createXYLineChart(java.lang.String title, java.lang.String xAxisLabel, java.lang.String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)

    ChartFrame frame1=new ChartFrame("XYLine Chart",chart);
After this we create the object of ChartFrame. It used to display a chart.

Here is the code of the Program :

import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.*;
import org.jfree.data.*;

public class xyLine{
public static void main(String arg[]){
  XYSeries series = new XYSeries("Average Weight");
  series.add(20.020.0);
  series.add(40.025.0);
  series.add(55.050.0);
  series.add(70.065.0);
  XYDataset xyDataset = new XYSeriesCollection(series);
  JFreeChart chart = ChartFactory.createXYLineChart
  ("XYLine Chart using JFreeChart""Age""Weight",
 xyDataset, PlotOrientation.VERTICAL, true, true, 
false);
  ChartFrame frame1=new ChartFrame("XYLine Chart",chart);
  frame1.setVisible(true);
  frame1.setSize(300,300);
  }
}

Output of the Program :

Download this Example

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 13, 2007

Ask Questions?    Discuss: XYLine Chart   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Alexandre
May 28, 2013
Sorting Vector

Hi, I succeeded ploting the graph, but when I try to add two vectors using a loop, it sorts the vector, but I don't want it sorted, what should I do? Thank you!
Chitra
August 27, 2013
Chart Label Font Changes

Is there a provision to change the chart X-axis Y-axis font type in line chart..? Kindly help me with the sample. Thanks
parth patel
March 22, 2014
Java Program to create chart from XY Coordinates

I Check this site but it has so much packages to create chart..Anyone send me the link of the packages of this program .. import org.jfree.chart.*; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.xy.*; import org.jfree.data.*; public class xyLine{ public static void main(String arg[]){ XYSeries series = new XYSeries("Average Weight"); series.add(20.0, 20.0); series.add(40.0, 25.0); series.add(55.0, 50.0); series.add(70.0, 65.0); XYDataset xyDataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart ("XYLine Chart using JFreeChart", "Age", "Weight", xyDataset, PlotOrientation.VERTICAL, true, true, false); ChartFrame frame1=new ChartFrame("XYLine Chart",chart); frame1.setVisible(true); frame1.setSize(300,300); } }
Abishek Arumugam
July 10, 2013
Java Program to create chart from XY Coordinates

I Check this site but it has so much packages to create chart..Anyone send me the packages of this program .. import org.jfree.chart.*; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.xy.*; import org.jfree.data.*; public class xyLine{ public static void main(String arg[]){ XYSeries series = new XYSeries("Average Weight"); series.add(20.0, 20.0); series.add(40.0, 25.0); series.add(55.0, 50.0); series.add(70.0, 65.0); XYDataset xyDataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart ("XYLine Chart using JFreeChart", "Age", "Weight", xyDataset, PlotOrientation.VERTICAL, true, true, false); ChartFrame frame1=new ChartFrame("XYLine Chart",chart); frame1.setVisible(true); frame1.setSize(300,300); } }
DMCA.com