tags:

views:

622

answers:

1

Hi,

I'd like to know if there is a way to detect when the mouse is over the graph line/lines and to be able to acces the data from the dataset corresponding to that point.

A: 

Getting this data depends on where you are using the chart. In a swing application use the mouse listeners from the panel that the chart is displayed in.

On a web page using an image you will not be able to get to the data (as it is only an image), but JFreeChart will generate an image map for you which can call java script on hover.

In a recent project I did something like:

     ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());  
  String pngLocation = Servlet.saveChartAsPNG(chart, 200, 200, info, request.getPortletSession());
      StringWriter sw = new StringWriter();
      ChartUtilities.writeImageMap(new PrintWriter(sw), pngLocation, info, false);

Here chart is a JFreeChart with the appropriate flags for what it is you are seeking to do (tool tips, url's, labels)

Adam