Jfreechart在chartPanel中创建工具提示 [英] Jfreechart create tooltip in chartPanel

查看:151
本文介绍了Jfreechart在chartPanel中创建工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在JFreechart中在图表鼠标上生成工具提示?
我试过了

How can I generate a tooltip on chart mouse over in JFreechart? I tried

chartPanel.setToolTipText("this is the string");

但这不起作用。我以前应该做别的事吗?例如

but this does not work. Am i supposed to do something else before? something like

chartPanel.createToolTip().

我在chartMouseMoved事件中调用这些方法。
感谢

I am calling these methods in the chartMouseMoved event. Thanks

推荐答案

最多 ChartFactory 方法包括 boolean tooltips 参数。只需查看你选择的工厂的源代码,看看如何实例化一个适合指定渲染器的默认工具提示生成器。

Most ChartFactory methods include a boolean tooltips parameter. Just look in the source for your factory of choice to see how to instantiate a default tooltip generator suitable for the designated renderer. You shouldn't need to handle the events yourself.

附录:您使用 createXYLineChart 时, StandardXYToolTipGenerator 默认提供。 DEFAULT_TOOL_TIP_FORMAT {0}:({1},{2}); MessageFormat 符号表示数据集系列。您可以在自己的生成器中使用这些符号,如 XYItemLabelGenerator ,或者您可以覆盖 generateToolTip()

Addendum: As you are using createXYLineChart, an instance of StandardXYToolTipGenerator is supplied by default. The DEFAULT_TOOL_TIP_FORMAT is {0}: ({1}, {2}); the MessageFormat symbols represent the dataset, series and item, respectively. You can use these symbols in your own generator, as shown in this XYItemLabelGenerator, or you can override generateToolTip() to return anything at all.

附录:下面是一个仅显示数据集的示例:

Addendum: Here's an example that shows just the dataset:

XYPlot plot = chart.getXYPlot();
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
renderer.setLegendItemToolTipGenerator(
    new StandardXYSeriesLabelGenerator("Legend {0}"));

这篇关于Jfreechart在chartPanel中创建工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆