Tooptip can't show in ServletDemo2ChartGenerator
Tooptip can't show in ServletDemo2ChartGenerator
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
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
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
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
Here is what part of my code:
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
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();
}
}
Thanks.
Regards,
mingjade
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
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