Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training Big Data and Hadoop Training Java Training  

How to show database values into graph using jsp?



Share on Google+Share on Google+

How to show database values into graph using jsp?
1 Answer(s)      4 years and 9 months ago
Posted in : JSP-Servlet

How to show database values into graph using jsp?

View Answers

November 5, 2012 at 11:12 AM

You need to download the jfreechart api and put the jar file inside the lib folder of apache tomcat. Then restart the tomcat server.

<%@ page import="java.sql.*" %>
<%@ page import="*" %>
<%@ page import="org.jfree.chart.ChartFactory" %>
<%@ page import="org.jfree.chart.ChartUtilities" %>
<%@ page import="org.jfree.chart.JFreeChart" %>
<%@ page import="org.jfree.chart.plot.PlotOrientation"%>
<%@ page import="*" %>
<%@ page import=""%>
<%@ page import="org.jfree.chart.ChartPanel"%>

String query="SELECT * from chart";
JDBCCategoryDataset dataset=new JDBCCategoryDataset("jdbc:mysql://localhost:3306/chart",

dataset.executeQuery( query);
JFreeChart chart = ChartFactory.createLineChart("Test", "Id", "Score",
                                dataset, PlotOrientation.VERTICAL, true, true, false);
                ChartPanel chartPanel = new ChartPanel(chart);
                chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
                ApplicationFrame f = new ApplicationFrame("Chart");

ChartUtilities.saveChartAsJPEG(new File("C:/chart.jpg"), chart, 400, 300);
catch (IOException e)
System.out.println("Problem in creating chart.");


Related Tutorials/Questions & Answers: