Tooptip can't show in ServletDemo2ChartGenerator

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
mingjade

Tooptip can't show in ServletDemo2ChartGenerator

Post by mingjade » Tue Sep 13, 2005 8:00 am

Hello,

May i know why can't the tooltip shown in this demo? I know that in the ChartPanel it will automatically show the tooltip, but why this can't shown in the web browser? Please advice.

Thanks.
Regards,
mingjade

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Tue Sep 13, 2005 8:35 am

Hi,

there is a fundamental difference between Swing (Client-Side, Standalone Java Application) and the web-browser. The web browser uses the generated HTML code to render everything. Depending on the generated HTML code your browser may or may not print tooltips. Look at the generated code; maybe an URL generator may generate an Anchor tag that will act as tooltip.

Regards,
Thomas

mingjade

Post by mingjade » Tue Sep 13, 2005 9:32 am

Hi,

Do you mean there is no way to show tool tip on the web browser? Can we use the setToolTipGenerator, but i do not know how to show it? May be you can give me some guidance how should i start or which method can be used to call tooltips on the web browser.

Thanks.
Regards,
mingjade

angel
Posts: 899
Joined: Thu Jan 15, 2004 12:07 am
Location: Germany - Palatinate

Post by angel » Tue Sep 13, 2005 10:20 am

Of course you can show tool tips on the web browser. Use the search and you will find many examples.

mingjade

Post by mingjade » Tue Sep 13, 2005 10:53 am

Hi,

I have been searching for example, but i can't find any way the do it? Can you please give some tips on this?

Thanks.
Regards,
mingjade

mingjade

Post by mingjade » Tue Sep 13, 2005 11:06 am

Here is what part of my code:

Code: Select all


private JFreeChart createChart() {
CategoryDataset dataset1 = readDataSet1();
CategoryDataset dataset2 = readDataSet2();
	        
JFreeChart chart = ChartFactory.createBarChart(
"Department Rolling",        // chart title
"Work Week"               // domain axis label
"Number of People",                  // range axis label
dataset1,                   // data
PlotOrientation.VERTICAL,
true,                    // include legend
true,                     // tooltips?
false                     // URL generator?  
);

// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
chart.setBackgroundPaint(Color.white);

// get a reference to the plot for further customisation...
CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF));
plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);


plot.setDataset(1, dataset2);
plot.mapDatasetToRangeAxis(1, 0);
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
			        
LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
renderer2.setToolTipGenerator(new StandardCategoryToolTipGenerator());
renderer2.setItemURLGenerator(new StandardCategoryURLGenerator("xy_chart.jsp","series","section"));
plot.setRenderer(1, renderer2);
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setUpperMargin(0.1);			
return chart;
    }

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

        OutputStream out = response.getOutputStream();
        try {
            String type = request.getParameter("type");
            String sql = request.getParameter("sql");

            JFreeChart chart = null;

            if (type.equals("abc")){
	chart = createChart();}
            if (chart != null) {
	ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
                response.setContentType("image/png");
                ChartUtilities.writeChartAsPNG(out, chart, 500, 300, info);
            }
        }
        catch (Exception e) {
            System.err.println(e.toString());
        }
        finally {
            out.close();
        }

    }
Then from the JSP i just call this servlet, why can't i get the toop tip? can you please let me know where i went wrong? Can i put the ChartRenderingInfo that way, will it able to collect the info?

Thanks.
Regards,
mingjade

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Tue Sep 13, 2005 11:37 am

Hi,

you are writing a single PNG binary stream. PNG images hold pixel data and cannot provide tooltips.

The information about the tooltip must be encoded in the HTML file referencing the PNG image. For the PNG image tag in the HTML file, you will also have to define an ImageMap (which tells the browser that certain areas of the image behave like anchor elements and therefore also show tooltips).

Look at that thread:
http://www.jfree.org/phpBB2/viewtopic.p ... ervlet+jsp

and there at psupa's posting from 26-07-04 05:11:32 you'll find an example.


Regards,
Thomas

mingjade

Post by mingjade » Wed Sep 14, 2005 4:16 am

Thanks Thomas. Anyhow, i tested with the example given and the pie chart shown succesffully but the tooltips or URL is not showing. Do you know what could went wrong?

Thanks.
Regards,
mingjade

pmlb
Posts: 31
Joined: Thu Aug 25, 2005 5:18 pm
Location: France

Post by pmlb » Thu Sep 15, 2005 3:57 pm

Did you try with different browsers?
In my case tooltips work fine with Mozilla 1.7.3 but don't show up with Netscape 4.73
Pierre-Marie

Locked