Custom XY Tool Tip Generator in JFreeChart

Using JFreeChart I added a custom xy tool tip generator to a scatter plot:

JFreeChart chart = ChartFactory.createScatterPlot( ... );
XYPlot plot = chart.getXYPlot();
XYItemRenderer renderer = plot.getRenderer();
CustomXYToolTipGenerator tipGenerator =
         new CustomXYToolTipGenerator();
List tipsMain = new ArrayList<>();
tipGenerator.addToolTipSeries(tipsMain);
renderer.setBaseToolTipGenerator(tipGenerator);

I then populated the data for the series and the tool tips:

XYSeries series1 = new XYSeries("S1");
for (TechBundle bundle : techBundles) {
    double cost = bundle.getCost();
    double fe   = bundle.getFE();
    series1.add(cost, fe);
    tipsMain.add(String.format("%s $%.0f %.2f",
            bundle.getBundleID(), cost, fe));
}

The problem was the tool tips were not correct for the point. Tool tip for point n would be shown for point m.

This is due to the fact that by default the xy series is automatically sorted (in ascending order of x-values). That sorting messed-up the alignment of the data and the tool tips. The fix is to turn-off the automatic sorting, which must be done when the series is constructed:

XYSeries series1 = new XYSeries("S1", false);