问题描述
如何在 JFreeChart
中在图表鼠标悬停时生成工具提示?我试过这个:
How can I generate a tooltip on chart mouse over in JFreeChart
?
I tried this:
chartPanel.setToolTipText("this is the string");
但这不起作用.我应该先做点别的吗?像这样:
but this does not work. Am I supposed to do something else before? Something like this:
chartPanel.createToolTip().
我在 chartMouseMoved
事件中调用这些方法.
I am calling these methods in the chartMouseMoved
event.
推荐答案
大多数 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
符号分别代表dataset
、series
和item
.您可以在自己的生成器中使用这些符号,如下所示 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.
附录:这是一个仅显示 dataset
的示例:
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屋!
更多推荐
[db:关键词]
发布评论