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

TimeSeries 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 Time series chart.

File Name  :  
com/bethecoder/tutorials/jfree_charts/tests/TimeSeriesExample.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.jfree_charts.tests;

import java.text.SimpleDateFormat;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;

public class TimeSeriesExample {

  public static void main(String[] args) {

    // Prepare the data set
    TimeSeries population = new TimeSeries("Indian Population");
    population.add(new Day(131961)439234771);
    population.add(new Day(131971)548159652);
    population.add(new Day(131981)683329097);
    population.add(new Day(131991)843387888);
    population.add(new Day(132001)1028610328);
    population.add(new Day(132011)1210193422);
    TimeSeriesCollection dataset = new TimeSeriesCollection(population);
    
    // Create the chart
    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Population of India""Date""Population", dataset,
        true, true, false);
    
    //Get the plot and set date format
    XYPlot plot = chart.getXYPlot();
    DateAxis axis = (DateAxisplot.getDomainAxis();
      axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    // Render the frame
    ChartFrame chartFrame = new ChartFrame("Simple TimeSeries Chart", chart);
    chartFrame.setVisible(true);
    chartFrame.setSize(600300);
  }
}
   

It gives the following output,
timeseries.jpg


                    Print

   



Books Recommendation

 
 
bl  br