Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


wilfredo
JFREE chart
1 Answer(s)      5 years and 6 months ago
Posted in : Java Beginners



Advertisement
View Answers

April 24, 2009 at 12:12 PM


Hi Friend,

Try the following code to display the dynamic data from the MySQL database on your chart.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">;

<%@ page import="java.awt.*" %>
<%@ page import="java.io.*" %>
<%@ page import="org.jfree.chart.*" %>
<%@ page import="org.jfree.chart.axis.*" %>
<%@ page import="org.jfree.chart.entity.*" %>
<%@ page import="org.jfree.chart.labels.*" %>
<%@ page import="org.jfree.chart.plot.*" %>
<%@ page import="org.jfree.chart.renderer.category.*" %>
<%@ page import="org.jfree.chart.urls.*" %>
<%@ page import="org.jfree.data.category.*" %>
<%@ page import="org.jfree.data.general.*" %>
<%@ page import="java.sql.*" %>

<%!
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://192.168.10.112:3306/";;
String username = "root";
String password = "root";
String dbName= "student";
%>
<%
Class.forName(driver);
Connection conn = DriverManager.getConnection(url+dbName, username, password);
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from general");
final DefaultPieDataset data = new DefaultPieDataset();


// Getting data from database
while(rs.next()){
data.setValue(rs.getString("name"), new Double(rs.getInt("age")));
}

JFreeChart chart = ChartFactory.createPieChart("Pie Chart for age of Students", data, true, true, false);

try {
final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

final File file1 = new File("../webapps/JSPExample/piechart.png");
ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
} catch (Exception e) {
out.println(e);
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<IMG SRC="piechart.png" WIDTH="600" HEIGHT="400"
BORDER="0" USEMAP="#chart">
</body>
</html>

We hope that this code will be very helpful in solving your problem.

Thanks
RoseIndia Team


Related Tutorials/Questions & Answers:
jfree chart
jfree chart  i need donut chart using jfree
JFree chart package error
JFree chart package error  hi, I had asked u abt the jfree chart package and done what u have said. Its working but its giving me error that some... the jcommon jar file and jfree jar file for the bar chart code. but now its giving
Advertisements
JFREE chart - Java Beginners
JFREE chart  how can i get the latest save image of my action class.....thanks,i want my chart to display dynamically from my database  Hi... database on your chart
Jfree chart problem - Swing AWT
Jfree chart problem  hello i have a problem related to jfree chart i have some data and i want to display data in two different chart stacked area chart and line chart both in a single frame. That is hybrid combination
Pie chart Jfree create error
Pie chart Jfree create error  hi........... thanks 4 ur help but when i am using the code which has a import file import org.jfree.chart.*; its giving me an error that " package org.jfree.chart does not exists " can u help me
Dynamin Jfree chart in jsp---error
Dynamin Jfree chart in jsp---error   While compiling this CODE...); JFreeChart chart = ChartFactory .createBarChart3D( "Stock Update", "runs...); try { ChartUtilities.saveChartAsJPEG(new File("c:\\chart.jpg"), chart
hybrid graph (jfree chart) - Swing AWT
hybrid graph (jfree chart)  hello i have a problem related to jfree chart.I want to display hybrid graph (Stacked Area and Line ).combination of stacked area chart and Line chart in one frame. Plese anybody help me out
Create a Pie Chart in jsp Page using JFree Chart
Create a Pie Chart in jsp Page using JFree Chart  Hello Sir I followed ur tutorial on "CREATE A PIE CHART IN JSP PAGE USING JFREE CHART... the pie chart report and after that save it to the desired location.Kindly help me
JFree 3D Bar Chart not displaying in JSP - Java3D
JFree 3D Bar Chart not displaying in JSP  Hi I am trying to run JFree 3D bar chart written in your site under link: http://www.roseindia.net/chartgraphs/3Dbarchart-in-jsppage.shtml This is not working. PNG file
display combination of a stacked area chart and line chart in one iframe using jfree - JSP-Servlet
display combination of a stacked area chart and line chart in one iframe using jfree  hello i have a problem related to jfree chart, i want to display combination of a stacked area chart and line chart in one iframe
Jfree exception
Jfree exception  import java.sql.*; import org.jfree.chart.... org.jfree.data.xy.*; import org.jfree.data.*; public class Chart{ public static... = new XYSeriesCollection(series); JFreeChart chart
Jfree exception
Jfree exception  import java.sql.*; import org.jfree.chart.... org.jfree.data.xy.*; import org.jfree.data.*; public class Chart{ public static... = new XYSeriesCollection(series); JFreeChart chart
JFREE error
JFREE error   hi......... the code for making chart is: WHICH..."); JFreeChart chart = ChartFactory.createBarChart ("BarChart using JFreeChart...(Color.red); ChartFrame frame1=new ChartFrame("Bar Chart",chart
jfree - Java Beginners
(300,300); } } For more information,Examples and Tutorials on jfree chart...jfree  how use the "import jfree" on jdk1.5.0_6,,? or how to plot... xyDataset = new XYSeriesCollection(series); JFreeChart chart
Jfree - Java Beginners
on jfree chart visit to : http://www.roseindia.net/chartgraphs/ Thanks...(20)); pieDataset.setValue("Six", new Integer(10)); JFreeChart chart = ChartFactory.createPieChart ("Pie Chart using JFreeChart", pieDataset, true,true
chart tutorial - Java3D
chart tutorial  Hi I need a JFree Chart class library in order to design a chart with java  Hi friend, For JFree Chart class library... information,Tutorials and Examples on JFree Chart visit to : http://www.roseindia.net
JFree - Java Beginners
JFree  how to import JFree to jdk1.6.0_05, not to new version,, or how to get java new version (that used JFree ) ? regads  Hi friend, For solving the problem visit to : http://www.roseindia.net/chartgraphs
jfree - Java Beginners
jfree  how use the "import jfree" on jdk1.5.0_6,, or how to plot data in xy line on jdk1.5.0_6
jfree missing import file
jfree missing import file  hi....... i have checked the jar file of jfree that import file of RECTANGLEINSETS is not there then what to do now? how to solve this problem? plz help?   Download jcommon-1.0.16.jar
jfree missing import file
jfree missing import file  hi....... i have checked the jar file of jfree that import file of RECTANGLEINSETS is not there then what to do now? how to solve this problem? plz help?   Download jcommon-1.0.16.jar
jfree missing import file
jfree missing import file  hi....... i have checked the jar file of jfree that import file of RECTANGLEINSETS is not there then what to do now? how to solve this problem? plz help?   Download jcommon-1.0.16.jar
jfree missing import file
jfree missing import file  hi....... i have checked the jar file of jfree that import file of RECTANGLEINSETS is not there then what to do now? how to solve this problem? plz help?   Download jcommon-1.0.16.jar
JFREE error again
JFREE error again  hi......... As i had asked u the jfree error i want to tel u that i have taken the both the jar files jfree and jcommon. but then also its giving me error i am able to compile the code but now when i am
Jfree create error
Jfree create error  hi.............. thanks 4 ur help. as u said i have downloaded both the jar files and placed in jdk1.5 lib folder. but then also its giving the same error can u tel me why this is happening? and also u
Jfree create error
Jfree create error  hi.............. thanks 4 ur help. as u said i have downloaded both the jar files and placed in jdk1.5 lib folder. but then also its giving the same error can u tel me why this is happening? and also u
Bar Chart in JSP - JSP-Servlet
Bar Chart in JSP  Hi I am creating Bar chart using Jfree charts in JSP. Please advise me how to customize it. Like controlling the colors, width for each bar, showing values above the bar .  hi friend, Use
hybrid chart(Stacked Area and Line ) - Swing AWT
hybrid chart(Stacked Area and Line )  hello i have a problem related to jfree chart i have some data and i want to display data in two different chart stacked area chart and line chart both in a single frame
i want to show timeline chart for three year in chart..
i want to show timeline chart for three year in chart..  I am using Jfree chart library to display chart in web pages. i want to show three year data in chart in 3 lines for three year in same chart. i am able to show
pie chart
pie chart  how to create pie chart using struts2
Pie chart
Pie chart  hi................. In my project i want to create a pie-chart by taking values at run time. As want to display it in pie chart form....   Java Swing PIE Chart
bar chart
bar chart  how to create a bar chart from values of the database and the string value should be the entities of the database??plzz help..needed badly
 

 

 

DMCA.com