I am trying to add a tooltip and url generator to a time sries graph. I have used the StandardXYItemRenderer and added a TimeSeriesToolTipGenerator object and a TimeSeriesURLGenerator object to the app. I cannot seem to find any documentation in this area and was hoping that by adding these objects the entities would automatically be added with tooltip and url generator. However they do not seem to be! I have been looking through the code but could find no help, what further steps do I need to do to get the tooltip and url enerator working?
cheers LEE
ToolTip and URL generator
Re: ToolTip and URL generator
Hi Lee,
Tooltips should be enabled by default in most chart types, when the chart is being displayed in a ChartPanel. Run the TimeSeriesDemo application and move the mouse point over one of the shapes to see this.
If you want to customise the format of the tool tips, then you should implement your own tool tip generator and call the setToolTipGenerator(...) method in the renderer. But if you are happy with the default format, there is no need to do this.
The URL generators are part of the HTML image map support. Richard Atkinson has been working on this (my initial implementation was pretty basic, Richard has improved it a lot). I haven't really used this code myself, but as I understand it the principle is similar - the URL generators give you an opportunity to customise the URL generated for each chart entity.
There are a few demo applications (ImageMapDemo1, 2 and 3 I think) that you might want to look through...
Regards,
DG
Tooltips should be enabled by default in most chart types, when the chart is being displayed in a ChartPanel. Run the TimeSeriesDemo application and move the mouse point over one of the shapes to see this.
If you want to customise the format of the tool tips, then you should implement your own tool tip generator and call the setToolTipGenerator(...) method in the renderer. But if you are happy with the default format, there is no need to do this.
The URL generators are part of the HTML image map support. Richard Atkinson has been working on this (my initial implementation was pretty basic, Richard has improved it a lot). I haven't really used this code myself, but as I understand it the principle is similar - the URL generators give you an opportunity to customise the URL generated for each chart entity.
There are a few demo applications (ImageMapDemo1, 2 and 3 I think) that you might want to look through...
Regards,
DG
Re: ToolTip and URL generator
Lee,
When creating the chart you need to pass in a ChartRenderingInfo object to be populated in order to create the image map. For example:
// Write the chart image to the temporary directory
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);
pw.flush();
I have created a sample WAR file to demonstrate charts with tooltips and drilldown, it is available at http://homepage.ntlworld.com/richard_c_ ... freechart/. That might make it easier to solve your problem.
Regards,
Richard...
David, could you host this WAR file under your Recent Contributions section of the site as a tooltip/drilldown example? Posts like this always get lost in the forum after a while.
When creating the chart you need to pass in a ChartRenderingInfo object to be populated in order to create the image map. For example:
// Write the chart image to the temporary directory
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);
pw.flush();
I have created a sample WAR file to demonstrate charts with tooltips and drilldown, it is available at http://homepage.ntlworld.com/richard_c_ ... freechart/. That might make it easier to solve your problem.
Regards,
Richard...
David, could you host this WAR file under your Recent Contributions section of the site as a tooltip/drilldown example? Posts like this always get lost in the forum after a while.
Re: ToolTip and URL generator
Hi Richard,
Yes, good suggestion, I'll do that.
Regards,
DG.
P.S. And thanks for your work (and frequent support) for this part of JFreeChart.
Yes, good suggestion, I'll do that.
Regards,
DG.
P.S. And thanks for your work (and frequent support) for this part of JFreeChart.
Re: ToolTip and URL generator
Thak you for the help guys, much appreciated. However, I was not very keen on having to create a new image each time I had to create an image map and have therefore extended the code slightly to not have to do this. It has probably been aided by the fact that I am using JSPs and custom tag libraries but Iam sure it would work for servlets too. Just to show everyone how I did it here is the code:
Test.jsp:
<%@ taglib uri="/META-INF/ct.tld" prefix="cti" %>
...
<td width=700>
<cti:graph map="true">
<IMG SRC="GraphImage.jsp" WIDTH="700" HEIGHT="440" BORDER="0" USEMAP="#GraphImage">
</cti:graph>
</td>...
GraphImage.jsp:
<%@ taglib uri="/META-INF/ct.tld" prefix="ctig" %>
<ctig:graph />
Graph.java: using tag name="graph" and one optional attribute="map"
ByteArrayOutputStream os;
if (map) {
JFreeChart chart = createTimeSeriesChart();
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
os = new ByteArrayOutputStream();
ChartUtilities.writeChartAsPNG(os, chart, WIDTH, HEIGHT, info);
pageContext.setAttribute(IMAGE, os, PageContext.SESSION_SCOPE);
PrintWriter out = new PrintWriter(pageContext.getOut());
ChartUtilities.writeImageMap(out, IMAGE, info);
return EVAL_BODY_INCLUDE;
}
else {
os = (ByteArrayOutputStream) pageContext.getAttribute(IMAGE, PageContext.SESSION_SCOPE);
if (os != null) {
getHttpResponse().setContentType("image/png");
OutputStream out = getHttpResponse().getOutputStream();
byte[] bytes = os.toByteArray();
for (int i = 0; i < bytes.length; i++) {
out.write(bytes);
}
return SKIP_BODY;
}
else {
throw new Exception("graph not saved");
}
}
Test.jsp:
<%@ taglib uri="/META-INF/ct.tld" prefix="cti" %>
...
<td width=700>
<cti:graph map="true">
<IMG SRC="GraphImage.jsp" WIDTH="700" HEIGHT="440" BORDER="0" USEMAP="#GraphImage">
</cti:graph>
</td>...
GraphImage.jsp:
<%@ taglib uri="/META-INF/ct.tld" prefix="ctig" %>
<ctig:graph />
Graph.java: using tag name="graph" and one optional attribute="map"
ByteArrayOutputStream os;
if (map) {
JFreeChart chart = createTimeSeriesChart();
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
os = new ByteArrayOutputStream();
ChartUtilities.writeChartAsPNG(os, chart, WIDTH, HEIGHT, info);
pageContext.setAttribute(IMAGE, os, PageContext.SESSION_SCOPE);
PrintWriter out = new PrintWriter(pageContext.getOut());
ChartUtilities.writeImageMap(out, IMAGE, info);
return EVAL_BODY_INCLUDE;
}
else {
os = (ByteArrayOutputStream) pageContext.getAttribute(IMAGE, PageContext.SESSION_SCOPE);
if (os != null) {
getHttpResponse().setContentType("image/png");
OutputStream out = getHttpResponse().getOutputStream();
byte[] bytes = os.toByteArray();
for (int i = 0; i < bytes.length; i++) {
out.write(bytes);
}
return SKIP_BODY;
}
else {
throw new Exception("graph not saved");
}
}