问题描述
如何在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
推荐答案
最多方法包括 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
时, 默认提供。 DEFAULT_TOOL_TIP_FORMAT
是 {0}:({1},{2})
; 符号表示数据集
,系列
和项
。您可以在自己的生成器中使用这些符号,如,或者您可以覆盖 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中创建工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!