JFreeChart 在 ChartPanel 中创建工具提示

编程入门 行业动态 更新时间:2024-10-26 06:33:30
本文介绍了JFreeChart 在 ChartPanel 中创建工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 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 符号分别代表datasetseriesitem.您可以在自己的生成器中使用这些符号,如下所示 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:关键词]

本文发布于:2023-03-31 20:43:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/813738.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:提示   工具   JFreeChart   ChartPanel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!