how to display tooltip ,plz see program its very urgent plzz

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
samaeinder
Posts: 10
Joined: Thu Jun 12, 2008 6:34 am

how to display tooltip ,plz see program its very urgent plzz

Post by samaeinder » Mon Jun 30, 2008 8:25 am

I am making the dashboard project, in which i have to display charts dynamicaly from database.With all yours support m able to do that but i m not able to display tooltip since after creating the chart m convering it into image ........i have put the code below plz help me out with any different way to display the graph so that i can able to see the tool tip
code is as follow

Code: Select all

package src;

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

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

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

import com.keypoint.PngEncoder;

public class MyChart extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		HttpSession session = req.getSession();
		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("DRE");
			while (rs.next()) {
				series.add(rs.getInt(1), rs.getInt(2));
			}

			XYDataset xyDataset = (XYDataset) new XYSeriesCollection(series);
			JFreeChart chart = ChartFactory.createXYLineChart(
					"XYLine Chart", "Release", "DRE",
					xyDataset, PlotOrientation.VERTICAL, true, true, false);
			session.setAttribute("chart", chart);
			res.setContentType("image/jpeg");
			BufferedImage buf = chart.createBufferedImage(640, 400, null);
			PngEncoder encoder = new PngEncoder(buf, false, 0, 9);
			res.getOutputStream().write(encoder.pngEncode());
		} catch (ClassNotFoundException e) {
			
			e.printStackTrace();
		} catch (SQLException e) {
		
			e.printStackTrace();
		} catch (IOException e) {
			
			
			e.printStackTrace();
		}
		getServletContext().getRequestDispatcher("chart.jsp").forward(req, res);

	}

	public void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		doPost(req, res);
	}

}
Chart.jsp

Code: Select all

<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@page import="org.jfree.chart.ChartRenderingInfo"; %>
<%@page import="org.jfree.chart.ChartUtilities"; %>
<%@page import="org.jfree.chart.JFreeChart";%>

<html>
    <body>
   <%HttpSession httpSession = request.getSession(true);
				JFreeChart chart = (JFreeChart) httpSession
						.getAttribute("chart");
				ChartRenderingInfo info = new ChartRenderingInfo();
				chart.createBufferedImage(640, 400, info);
				String imageMap = ChartUtilities.getImageMap("map", info);%> <%=imageMap%>

    
    
    </body>
</html>

I hope u guys understand my problem ........
plz help me out.....
Thanks in advance......

Wetzerk
Posts: 14
Joined: Thu Feb 07, 2008 3:54 pm

Post by Wetzerk » Tue Jul 01, 2008 5:19 pm

what does the rendered html look like?

joolz
Posts: 56
Joined: Thu Nov 17, 2005 2:38 am
Location: Australia

Post by joolz » Wed Jul 02, 2008 12:12 am

In your jsp, ensure that you have something along the following lines (this is from servlet code, so you may need to adjust to suit):

Code: Select all

<img src="MyChart.png" alt="" usemap="#chart" />
If that doesn't help, please post the resulting output of your jsp

samaeinder
Posts: 10
Joined: Thu Jun 12, 2008 6:34 am

Post by samaeinder » Wed Jul 02, 2008 6:08 am

Thanks a lot guys ........
i m able to solve the problem will all ur help
Thanks
SAM

Locked