0

I have added tooltips into line chart using StandardXYToolTipGenerator.

final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
plot.setRenderer(renderer);
renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());

It works well, but I need to move cursor to the precise point to show the tooltip. I hope I can do something like Plotly where the tooltips of all series will be shown along the x-axis.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Sam
  • 1,252
  • 5
  • 20
  • 43

1 Answers1

1

Assuming ChartFactory.createXYLineChart(), you can enable tooltips by setting the tooltips parameter to true. Note how the factory's source resembles your fragment.

Once enabled, it may help to let the renderer make the corresponding shapes visible:

final XYPlot plot = (XYPlot) chart.getPlot();
XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
r.setBaseShapesVisible(true);

In some cases, you may even want to enlarge the shapes:

r.setSeriesShape(0, ShapeUtilities.createTranslatedShape(
    new Rectangle(12, 12), -6, -6));

A complete example is shown here. Note that the ChartMouseListener can respond to an AxisEntity, too.

image

You can also selectively change the shape, as shown here. You can access the displayed tooltip, as shown here.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 1
    Actually what you mention did not answer my question. I want to implement something like https://codepen.io/plotly/pen/GJPjeY where the multiple tooltips will be show on the data point when mouse hover over. Anyway, thanks. – Sam Aug 22 '17 at 01:44
  • These are just some alternatives. You can display anything you want in your `ChartMouseListener` for a `ChartEntity` of type `AxisEntity`. I'd probably update an adjacent `TableModel`. – trashgod Aug 22 '17 at 09:41