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

Home Answers Viewqa JSP-Servlet How to show database values into graph using jsp?

Have Programming Question? Ask it here!

How to show database values into graph using jsp?
1 Answer(s)      a year and 8 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: