Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


Java Tutorials



Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

WaterFall Chart


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

Description of Program :

For creating a WaterFall chart we use the object of DefaultCategoryDataset. After creating the object of DefaultCategoryDataset we add some data in this object by invoking addValue() method. In this example you learn some more interactive features of JFreeChart like set the GridLines color of chart and adjust the color the title etc.

Description of Code :

For defining a dataset for WaterFall chart we have to create an object of DefaultCategoryDataset type :
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();

After creating the instance of dataset then we have to add the data in the data set by invoking the method addValue().
        addValue(3.0, “Salary”, “Rahul”);
First argument specifies the salary of a employee and the second argument specify what will appear in the legend to the meaning of the Waterfall chart.

        JFreeChart chart = ChartFactory.createWaterfallChart("Comparison between Employee", "Employee", "Salary", dataset, PlotOrientation.VERTICAL, true, true, false);
After added the data in dataset we create the WaterFall chart by invoking the createWaterfallChart() 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 createWaterfallChart(java.lang.String title, java.lang.String categoryAxisLabel, java.lang.String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);

Above method is used to set the color of chart title

        CategoryPlot p = chart.getCategoryPlot(); 
Above method is used to get the object of the Plot for Waterfall Chart. GetCategoryPlot() is method of the JFreeChart class and it returns the object of CategoryPlot type.

Above method is used to set the color of plot Gridlines.

Above method is used to set the flag that controls the Gridlines are drawn or not against the domain axis.

Above method is used to set the color of Gridlines against the domain axis. 

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

Here is a code of the Program :

import java.awt.*;
import org.jfree.chart.*;
import org.jfree.data.category.*;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.*;
import org.jfree.data.*;
import org.jfree.chart.renderer.category.*;
import org.jfree.chart.plot.*;

public class Waterfall{
public static void main(String arg[]){
  DefaultCategoryDataset dataset = new DefaultCategoryDataset();
  JFreeChart chart = ChartFactory.createWaterfallChart
"Comparison between Employees","Employee""Salary"
  dataset, PlotOrientation.VERTICAL, true,true, 
  CategoryPlot p = chart.getCategoryPlot()
  ChartFrame frame1=new ChartFrame("WaterFall Chart",chart);

Output of the Program :

Download this Program


Ask programming questions?



Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (post your own) View All Comments Latest 10 Comments:

they should well define and organized.

Posted by mzee khalfan on Friday, 10.9.09 @ 17:25pm | #91613

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name


Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.

[an error occurred while processing this directive]