Guidance required in showing Tooltip Text

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
nsurendiran
Posts: 17
Joined: Mon Oct 26, 2009 12:07 pm
antibot: No, of course not.

Guidance required in showing Tooltip Text

Post by nsurendiran » Wed Nov 04, 2009 8:32 am

Hi All,

I tried the ItemLabelDemo1.java and I got the Label and the Tooltip shown in the chart perfectly.

I need to show the tooltip in my Gantt, drawn in browser. For that I used saveChartasPNG method and displaying the image using <img> tag.

But in this case I am getting the Labels but not the tooltip. I knew that from the save image fetching the tooltip is not possible.

But then how can I get the tooltip text in this case? I tried image display to avoid zooming the chart to real size. Otherwise the actual size is restricted to browser's size. But when I draw an image its fine.

Somebody please throw some light on this.

Thanks
Suren

remiohead
Posts: 201
Joined: Fri Oct 02, 2009 3:53 pm
antibot: No, of course not.

Re: Guidance required in showing Tooltip Text

Post by remiohead » Mon Nov 09, 2009 6:15 pm

Tooltips won't display in the browser because its just an image. Have you thought about using an applet?

chechaquo
Posts: 10
Joined: Tue Oct 28, 2008 12:42 pm

Re: Guidance required in showing Tooltip Text

Post by chechaquo » Mon Nov 09, 2009 7:54 pm

You should get the map from the chart and then use this map for tooltips.

nsurendiran
Posts: 17
Joined: Mon Oct 26, 2009 12:07 pm
antibot: No, of course not.

Re: Guidance required in showing Tooltip Text

Post by nsurendiran » Tue Nov 10, 2009 4:28 am

Hi remiohead,
We are not using Applets in our application. So I cannot think about using that one.

Hi chechaquo,

I tried displaying a map, but I didnt get the output to the screen. Image itself not displayed. I know I did something wrong.
I tried the sample code suggested in the following example.
But there the writeImageMap method is commented out. I am blank now.

So any help would be appreciated.

Thanks
Suren

chechaquo
Posts: 10
Joined: Tue Oct 28, 2008 12:42 pm

Re: Guidance required in showing Tooltip Text

Post by chechaquo » Wed Nov 11, 2009 8:53 am

here is a quick sample code, not the best approach perhaps, but still... :roll: u can do something similar :roll:

Code: Select all

<%@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">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>

    </head>
    <body>

        <h1>Hello World!</h1>
        <img src="/JfreechartTest/ChartServlet" alt="test" usemap="#test"  onload="ajaxFunction()"/>
        <div id="map">

        </div>

        <script type="text/javascript">
// this is function from w3school tutorial, which is modified according to our needs :)
            function ajaxFunction()
            {
                var xmlhttp;
                if (window.XMLHttpRequest)
                {
                    // code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp=new XMLHttpRequest();
                }
                else
                {
                    // code for IE6, IE5
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange=function()
                {
                    if(xmlhttp.readyState==4)
                    {
                        var element= document.getElementById("map");
                        element.innerHTML=xmlhttp.responseText;

                    }
                }
                xmlhttp.open("GET","/JfreechartTest/LoadMapServlet",true);
                xmlhttp.send(null);
            }


           
        </script>
    </body>
</html>
Here are servlets...

Code: Select all

public class ChartServlet extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("image/jpg;");
        ServletOutputStream out=response.getOutputStream();
        try {
            DefaultPieDataset dataset = new DefaultPieDataset();
            dataset.setValue("One", new Double(1));
            dataset.setValue("Two", new Double(2));
            JFreeChart chart = ChartFactory.createPieChart(
                    "Pie Chart ", // chart title
                    dataset, // data
                    true, // include legend
                    true,
                    false);
            ChartRenderingInfo info = new ChartRenderingInfo();
            ChartUtilities.writeChartAsJPEG(out, chart, 400, 500, info);
            String map=ChartUtilities.getImageMap("test", info);
            String map1=map.replaceAll("\n", " ");
            String map2=map1.replaceAll("\r", " ");
            request.getSession().setAttribute("map", map2);
            
           

        } finally {
            out.flush();
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}

Code: Select all

public class LoadMapServlet extends HttpServlet {
   
    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {     
            String map=(String)request.getSession().getAttribute("map");
            out.println(map);
        } finally { 
            out.close();
        }
    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
:roll:

Locked