I m getting problem in displaying charts and m not exactly able to find the problem


plz plz help me wher i m wrong plzzzzzzzzzzzzzzzzzzzzzzz
its very urgent............--------

---------------------

package src;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.http.HttpSession;


import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;


import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.servlet.ServletUtilities;

import org.jfree.data.XYDataset;
import org.jfree.data.XYSeries;
import org.jfree.data.XYSeriesCollection;



public class WebHitChart {
	public static String generateXYChart(HttpSession session,
		PrintWriter pw) {
	String filename = null;

	try {
		final String query = "select target_milestone,dre from dre_cal where product='WEBSITES' ";
		Connection conn;

		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		conn = DriverManager.getConnection("jdbc:odbc:dreDSN");
		Statement statement = conn.createStatement();
		System.out.println("the value of conn ...." + conn);
		System.out.println("start");
		ResultSet rs = statement.executeQuery(query);
		XYSeries series = new XYSeries("Average Weight");
		while (rs.next()) {
			series.add(rs.getInt(1), rs.getInt(2));
		}

		XYDataset xyDataset = (XYDataset) new XYSeriesCollection(series);
		JFreeChart chart = ChartFactory.createXYLineChart(
				"XYLine Chart using JFreeChart", "Age", "Weight",
				xyDataset, PlotOrientation.VERTICAL, true, true, false);

		ChartRenderingInfo info = new ChartRenderingInfo(
				new StandardEntityCollection());
		filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info,
				session);

		//  Write the image map to the PrintWriter
		ChartUtilities.writeImageMap(pw, filename, info, false);
		pw.flush();

	} catch (Exception e) {
		System.out.println("Exception - " + e.toString());
		e.printStackTrace(System.out);
		filename = "public_error_500x300.png";
	}
	return filename;
}

------------------------------------------------------

<%@ page import = "src.*" %>
<%@ page import = "java.io.PrintWriter" %>
<%                  
     String filename = WebHitChart.generateXYChart(session, new PrintWriter(out));
	String graphURL = request.getContextPath() + "/WebHitChart.do?filename=" + filename;
%>
<html>
<body>
    <img src="<%= graphURL %>" width=500 height=300 border=0 usemap="#<%= filename %>">
 </body>
 </html>

------------------------------------------------------------

<servlet>
    <servlet-name>somename</servlet-name>
    <servlet-class>src.WebHitChart</servlet-class>
  </servlet>
   <servlet-mapping>
        <servlet-name>somename</servlet-name>
        <url-pattern>/WebHitChart.do</url-pattern>
    </servlet-mapping>

---------------------------------

Error i m getting on jsp page is

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: An exception occurred processing JSP page /xy_area.jsp at line 4

1: <%@ page import = "src.*" %>
2: <%@ page import = "java.io.PrintWriter" %>
3: <%                  
4:      String filename = WebHitChart.generateXYChart(session, new PrintWriter(out));
5: 	String graphURL = request.getContextPath() + "/WebHitChart.do?filename=" + filename;
6: %>
7: <html>


Stacktrace:
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause 

javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/jfree/data/XYDataset
	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
	org.apache.jsp.xy_005farea_jsp._jspService(xy_005farea_jsp.java:76)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause 

java.lang.NoClassDefFoundError: org/jfree/data/XYDataset
	org.apache.jsp.xy_005farea_jsp._jspService(xy_005farea_jsp.java:58)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.


--------------------------------------------------------------------------------

plzz help me...........

i have tried with this way also still getting plz see the code

package src;

import java.awt.image.BufferedImage;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.XYDataset;
import org.jfree.data.XYSeries;
import org.jfree.data.XYSeriesCollection;

public class XYChartExample2 {
	

	public XYChartExample2() {
	}

	public  String getChartViewer(HttpServletRequest request,
			HttpServletResponse response) {

		final String query = "select target_milestone,dre from dre_cal where product='WEBSITES' ";
		Connection conn;

		try {
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			conn = DriverManager.getConnection("jdbc:odbc:dreDSN");
			Statement statement = conn.createStatement();
			System.out.println("the value of conn ...." + conn);
			System.out.println("start");
			ResultSet rs = statement.executeQuery(query);
			XYSeries series = new XYSeries("Average Weight");
			while (rs.next()) {
				series.add(rs.getInt(1), rs.getInt(2));
			}

			XYDataset xyDataset = (XYDataset) new XYSeriesCollection(series);
			JFreeChart chart = ChartFactory.createXYLineChart(
					"XYLine Chart using JFreeChart", "Age", "Weight",
					xyDataset, PlotOrientation.VERTICAL, true, true, false);

			ChartRenderingInfo info = null;
			HttpSession session = request.getSession();

			response.setContentType("text/html");
			info = new ChartRenderingInfo(new StandardEntityCollection());
			BufferedImage chartImage = chart.createBufferedImage(550, 350,
					info);
			session.setAttribute("chartImage", chartImage);
			//  Write the image map to the PrintWriter
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		String pathInfo = "http://";
		pathInfo += request.getServerName();
		int port = request.getServerPort();
		pathInfo += ":" + String.valueOf(port);
		pathInfo += request.getContextPath();
		String chartViewer = pathInfo + "/servlet/ChartViewer";
		return chartViewer;
	}
}

-----------------------------

<%@ page import = "src.XYChartExample2" %>
<%String chartViewer = XYChartExample2.g--);%> 
<html>
<body>
 <img src="<%=chartViewer%>" border=0 usemap="#imageMap"> 
 </body>
 </html>

-------------------------

error m getting

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 2 in the jsp file: /xytest.jsp
Cannot make a static reference to the non-static method getChartViewer(HttpServletRequest, HttpServletResponse) from the type XYChartExample2
1: <%@ page import = "src.XYChartExample2" %>
2: <%String chartViewer = XYChartExample2.getChartViewer(request, response);%> 
3: <html>
4: <body>
5:  <img src="<%=chartViewer%>" border=0 usemap="#imageMap"> 


Stacktrace:
	org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
	org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
	org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

Hey check this out plz or tell me wat else i have to do ..........

Thanks
Sam

The error message "Cannot make a static reference to the non-static method" says it all. You need to first instantiate the XYChartExample2 class before invoking its method. BTW, scriptlets are bad and knowing the basics of Java helps before jumping into J2EE.

and it seems the kid also misses a basic understanding of classpaths, server configuration, and a lot of other things quite apart from not knowing Java and having the terribly bad idea of using scriptlets.

And it gets worse. The kid creates the chart (or tries to) as a file and then tries to do something unmentionable with it (at least the kid doesn't mention what it does with it, so I assume it's unmentionable).
Far easier to create a servlet that streams the chart and call that from an <img> tag.

Thanks boss.......
I m able to display the graph now......
but i have to work hard to make me conformtable with java ...........

ur suggestions make a worth for me, thanks for spending time on my issues.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.