geetha
graphs/charts
1 Answer(s)      3 years and 6 months ago
Posted in : JSP-Servlet

View Answers

November 18, 2009 at 4:47 PM


Hi Friend,

We have used jfreechart library to create a bar graph. And the chart displays the database values.If you want to download the jar files,please visit the following link:

http://www.roseindia.net/chartgraphs/jfreechart-introduction.shtml

Here is the code:

import java.sql.* ;
import java.io.* ;
import org.jfree.chart.ChartFactory ;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart ;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.* ;
import org.jfree.data.jdbc.JDBCCategoryDataset;

public class Chart{
public static void main(String[]args) throws Exception{


String query="SELECT * from chart";
JDBCCategoryDataset dataset=new JDBCCategoryDataset("jdbc:mysql://localhost:3306/test";;,
"com.mysql.jdbc.Driver","root","root");

dataset.executeQuery( query);
JFreeChart chart = ChartFactory .createBarChart3D(
"Test",
"Id",
"Score",
dataset,
PlotOrientation.VERTICAL,true, true, false);
try
{
ChartUtilities.saveChartAsJPEG(new File("C:/chart.jpg"), chart, 400, 300);
}
catch (IOException e)
{
System.out.println("Problem in creating chart.");
}
}
}

Thanks









Related Pages:
graphs/charts - JSP-Servlet
graphs/charts  hi, How to create a graph/chart in java by reading values from my sql database.   Hi Friend, Try the following code: import java.sql.* ; import java.io.* ; import org.jfree.chart.ChartFactory
graphs/charts - JSP-Servlet
graphs/charts  hi frens, How to create a bar graph by reading values from mysql database. Please help me out...   Hi Friend, We have used jfreechart library to create a bar graph. And the chart displays
Introduction to Graphs and Charts
Introduction to Graphs and Charts       Why Charts and GraphsGraphs... difficult and tedious process. All forms of Graphs and Charts embodies some Visual
Types of Graphs and Charts
Types of Graphs and Charts       There are many types of graphs and charts.... Line graphs: A line graph is a way of representing two pieces of information
Chart & Graphs Tutorials in Java
;     Best collection of Graphs and Charts Tutorials... to Charts & Graphs Graphs and Charts is the most efficient method...; Types of Charts There are many types of graphs and charts
What is Web Graphics
depiction next to them. It is better to use logos, cartoons, graphs and charts where they make a reasonable sense. Basics Tips

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.