XYDotRender is new for JFreeChart 0.9.4. I use it to generate my Scatter plot. However, the tooltip and url link is not there. It took me some time to find out that the XYDotRenderer is not completed... you have to physically add some code to fulfil the functionality of tooltip and url link generation. Here is the code I have, in case someone need it:
package org.cag.web.chart;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Stroke;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import com.jrefinery.data.XYDataset;
import com.jrefinery.chart.*;
import com.jrefinery.data.XYDataset;
import com.jrefinery.chart.entity.EntityCollection;
import com.jrefinery.chart.entity.XYItemEntity;
import com.jrefinery.chart.tooltips.XYToolTipGenerator;
import com.jrefinery.chart.tooltips.StandardXYToolTipGenerator;
import com.jrefinery.chart.urls.XYURLGenerator;
public class XYMYDotRenderer extends AbstractXYItemRenderer
implements XYItemRenderer {
/**
* Constructs a new renderer.
*/
public XYMYDotRenderer() {
}
/**
* Draws the visual representation of a single data item.
*
* @param g2 the graphics device.
* @param dataArea the area within which the data is being drawn.
* @param info collects information about the drawing.
* @param plot the plot (can be used to obtain standard color information etc).
* @param domainAxis the domain (horizontal) axis.
* @param rangeAxis the range (vertical) axis.
* @param data the dataset.
* @param series the series index.
* @param item the item index.
* @param crosshairInfo information about crosshairs on a plot.
*/
public void drawItem(Graphics2D g2,
Rectangle2D dataArea,
ChartRenderingInfo info,
XYPlot plot,
ValueAxis domainAxis,
ValueAxis rangeAxis,
XYDataset data,
int series,
int item,
CrosshairInfo crosshairInfo) {
// setup for collecting optional entity info...
Shape entityArea = null;
EntityCollection entities = null;
if (info != null) {
entities = info.getEntityCollection();
}
Paint seriesPaint = plot.getSeriesPaint(series);
Stroke seriesStroke = plot.getSeriesStroke(series);
g2.setPaint(seriesPaint);
g2.setStroke(seriesStroke);
// get the data point...
Number xn = data.getXValue(series, item);
Number yn = data.getYValue(series, item);
if (yn != null) {
double x = xn.doubleValue();
double y = yn.doubleValue();
double transX = domainAxis.translateValueToJava2D(x, dataArea);
double transY = rangeAxis.translateValueToJava2D(y, dataArea);
g2.drawRect((int) transX, (int) transY, 1, 1);
// add an entity for the item...
if (entities != null) {
if (entityArea == null) {
entityArea = new Rectangle2D.Double(transX - 2, transY - 2, 4, 4);
}
String tip = "";
if (getToolTipGenerator() != null) {
tip = getToolTipGenerator().generateToolTip(data, series, item);
}
String url = null;
if (getURLGenerator() != null) {
url = getURLGenerator().generateURL(data, series, item);
}
XYItemEntity entity = new XYItemEntity(entityArea, tip, url, series, item);
entities.addEntity(entity);
}
// do we need to update the crosshair values?
if (domainAxis.isCrosshairLockedOnData()) {
if (rangeAxis.isCrosshairLockedOnData()) {
// both axes
crosshairInfo.updateCrosshairPoint(x, y);
}
else {
// just the horizontal axis...
crosshairInfo.updateCrosshairX(x);
}
}
else {
if (rangeAxis.isCrosshairLockedOnData()) {
// just the vertical axis...
crosshairInfo.updateCrosshairY(y);
}
}
}
}
}
By the way, I am using Solaris 8 and JDK1.4, tomcat 4.04. The servlet example by Richard Atkinson is great. I can generate image map from my oracle database entries..., no additional packages(except jcommon and jfreechart) are needed to generate png image in this headless environment.
JFreechart is a great project... but sometimes, you have to do some coding/modification yourself, probably that is the most advantage of open source projects.
Tooltip and url for XYDotRenderer
Re: Tooltip and url for XYDotRenderer
Thanks for the code, I will incorporate your changes for 0.9.5.
You are right about doing coding/modifications yourself...sometimes you need to do this, and that's why having the source code is essential.
Richard Atkinson has done some fantastic work with the HTML image map generation, there is a link to his demo page on the main JFreeChart page, but I'll add it here also:
http://homepage.ntlworld.com/richard_c_ ... freechart/
Regards,
Dave Gilbert
You are right about doing coding/modifications yourself...sometimes you need to do this, and that's why having the source code is essential.
Richard Atkinson has done some fantastic work with the HTML image map generation, there is a link to his demo page on the main JFreeChart page, but I'll add it here also:
http://homepage.ntlworld.com/richard_c_ ... freechart/
Regards,
Dave Gilbert