JFREE chart

JFREE chart

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
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
(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
Artifacts of jfree
List of Artifacts of jfree maven depenency
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
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
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
Version of jfree>jfreechart dependency
Version of jfree>jcommon dependency
Version of jfree>jfreereport dependency
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
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
pie chart
pie chart  how to create pie chart using struts2
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
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
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
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
Version of jfree>jfreechart-experimental dependency
Version of jfree>jfreechart-swt dependency
Version of jfree>jfreereport-ext dependency
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
ModuleNotFoundError: No module named 'chart'
ModuleNotFoundError: No module named 'chart'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'chart' How to remove the ModuleNotFoundError: No module named 'chart'
draw chart in web application
draw chart in web application  how to draw bar chat from the record store in database? i.e. draw the bar chart according to selected record
Version of com.intersult>chart dependency
List of Version of com.intersult>chart dependency
Version of be.ceau>chart dependency
List of Version of be.ceau>chart dependency
Bar chart implementation in PHP
Bar chart implementation in PHP  How to implements reports in bar graphs by using PHP
Clickable chart with Tool Tip
Clickable chart with Tool Tip  Can we generate the charts with tooltip and onclick events using jfreechart in jsps and servlets
surface chart - Java3D
surface chart  i have to make a surface chart of a piece of land with data given for each point in the xy plane....the chart should be such that the areas with different data range should show up in different colour. seriously
3d pie chart - Java3D
3d pie chart  Dear Sir, i want to create 3d pie chart using jsp, i have some code for 2d pie chart in jsp and 3d pie chart in applet. for 2d pie chart my jsp page is running properly but for 3d i used some code from applet
Maven Repository/Dependency: jfree | jfreechart
Maven Repository/Dependency of Group ID jfree and Artifact ID jfreechart. Latest version of jfree:jfreechart dependencies. # Version Release Date 1 0.9.21 01 Aug 2005
Maven Repository/Dependency: jfree | jcommon
Maven Repository/Dependency of Group ID jfree and Artifact ID jcommon. Latest version of jfree:jcommon dependencies. # Version Release Date 1 1.0.16 25 Sep 2011
Maven Repository/Dependency: jfree | jfreereport
Maven Repository/Dependency of Group ID jfree and Artifact ID jfreereport. Latest version of jfree:jfreereport dependencies. # Version Release Date 1 0.8.5-5 19 Oct
line chart from database in jsp
line chart from database in jsp  how can i create line chart from database in jsp code

Ads