Mouse over graphics in jfreechart

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

0


a source to share


1 answer


Getting this data depends on where you are using the chart. In a swing application, use mouse listeners from the pane that displays the chart.

On a web page using an image, you won't be able to get the data (since it is only an image), but JFreeChart will create an image map for you that can call the 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 appropriate flags for what you are trying to do (tooltips, urls, labels)

0


a source







All Articles