In a JFreeChart x-y scatter chart I have two series of data. I needed to add custom tool tips
CustomXYToolTipGenerator for each series. The first approach I tried I never was able to get it to work:
XYPlot plot = ...; XYItemRenderer renderer = plot.getRenderer(); List<String> tips1 = ...; List<String> tips2 = ...; CustomXYToolTipGenerator tipGenerator1 = new CustomXYToolTipGenerator(); tipGenerator1.addToolTipSeries(tips1); CustomXYToolTipGenerator tipGenerator2 = new CustomXYToolTipGenerator(); tipGenerator2.addToolTipSeries(tips2); renderer.setBaseToolTipGenerator(null); renderer.setSeriesToolTipGenerator(0, tipGenerator1); renderer.setSeriesToolTipGenerator(1, tipGenerator2);
The tool tips for the first series would work, but there would be no tool tips for the second series.
Luckily, there is a second approach, which worked:
CustomXYToolTipGenerator tipGenerator = new CustomXYToolTipGenerator(); tipGenerator.addToolTipSeries(tips1); tipGenerator.addToolTipSeries(tips2); renderer.setBaseToolTipGenerator(tipGenerator);
If I ever figure out why the first approach did not work, I will update this post. If anybody has an idea, please leave a comment! Thanks!