Sam
Sam

Reputation: 1327

JFreeChart multiple tooltips along x-axis

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.

Upvotes: 0

Views: 409

Answers (1)

trashgod
trashgod

Reputation: 205775

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.

Upvotes: 1

Related Questions