http://ltc603.iteye.com/blog/30207
http://langhua9527.iteye.com/blog/395244
http://chinaxxren.iteye.com/blog/701297
http://hoocy.iteye.com/blog/327066
http://www.iteye.com/wiki/topic/360994
public String getToolTipText(MouseEvent e) {
// TODO Auto-generated method stub
// return super.getToolTipText(e);
Point2D p = translateScreenToJava2D(e.getPoint());
ChartRenderingInfo info = getChartRenderingInfo();
Rectangle2D dataArea = info.getPlotInfo().getDataArea();
// check if the mouse is really in the data area
if (dataArea.contains(p) == false) {
return null;
}
XYPlot plot = (XYPlot) chart.getPlot();
ValueAxis domainAxis = plot.getDomainAxis();
RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
double chartX = domainAxis.java2DToValue(p.getX(), dataArea,
domainAxisEdge);
ValueAxis yAxis = plot.getRangeAxis();
RectangleEdge yAxisEdge = plot.getRangeAxisEdge();
double chartY = yAxis.java2DToValue(p.getY(), dataArea, yAxisEdge);
String value = String.format("x = %.1f, y= %.1f", chartX, chartY);
// return String.valueOf(chartX);
return value;
}
Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
Point2D p = chartPanel.translateScreenToJava2D(pt);
double chartX = xyplot.getDomainAxis().java2DToValue(p.getX(), dataArea, xyplot.getDomainAxisEdge());
double chartY = xyplot.getRangeAxis().java2DToValue(p.getY(), dataArea, xyplot.getRangeAxisEdge());
chartPanel
.addChartMouseListener(new org.jfree.chart.ChartMouseListener() {
public void chartMouseClicked(ChartMouseEvent evt) {
try {
if (evt.getChart() != null
& evt.getEntity() != null) {
CategoryItemEntity cie = (CategoryItemEntity) evt
.getEntity();
if (cie.getCategory() == null)
return;
if (cie.getCategoryIndex() >= 0) {
cie = (CategoryItemEntity) evt.getEntity();
int i = cie.getCategoryIndex();
System.out.println("Your Selected Index > "
+ i);
}
} else
return;
} catch (Exception ce) {
System.out.println("Error" + ce);
}
}
public void chartMouseMoved(ChartMouseEvent event) {
int x = event.getTrigger().getX();
int y = event.getTrigger().getY();
ChartEntity entity = event.getEntity();
if (entity != null) {
System.out.println("Mouse moved: " + x + ", " + y
+ ": " + entity.toString());
} else {
System.out.println("Mouse moved: " + x + ", " + y
+ ": null entity.");
}
}
});