Chinaunix首页 | 论坛 | 博客
  • 博客访问: 207972
  • 博文数量: 73
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 750
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-13 18:32
文章分类

全部博文(73)

文章存档

2009年(1)

2008年(72)

我的朋友

分类: Java

2008-04-04 21:02:43

Overview
JFreeChart includes mechanisms for generating, collecting and displaying tool tips for individual components of a chart.
In this section, I describe:
• how to generate tool tips (including customisation of tool tips);
• how tool tips are collected;
• how to display tool tips;
• how to disable tool tips if you don’t need them;

Generating Tool Tips
 
保证tooltip是在绘制chart同时产生的
  If you want to use tool tips, you need to make sure they are generated as your chart is being drawn.
You do this by setting a tool tip generator for your plot or, in many cases, the plot’s item renderer.
 
#以ChartS为例演示tooltip的使用
#PieChart
The PiePlot class generates tool tips using the PieToolTipGenerator interface.A standard implementation (StandardPieToolTipGenerator) is provided, and you are free to create your own implementations.
  To set the tool tip generator, use the following method in the PiePlot class:
public void setToolTipGenerator(
  PieToolTipGenerator generator);
  Sets the tool tip generator for the pie chart. If you set this to null, no tool tips will be generated.

#Category Charts
 
Category charts—including most of the bar charts generated by JFreeChart—are based on the CategoryPlot class and use a CategoryItemRenderer to draw each data item.  
  The CategoryToolTipGenerator
interface specifies the method via which the renderer will obtain tool tips (if required).
  To set the tool tip generator for a category plot’s item renderer, use the following method (defined in the AbstractCategoryItemRenderer class):
  public void setToolTipGenerator(
    CategoryToolTipGenerator generator);

#XY Charts
 
XY charts—including scatter plots and all the time series charts generated by JFreeChart—are based on the XYPlot class and use an XYItemRenderer to draw each data item.
  The renderer generates tool tips (if required) using an XYToolTipGenerator.
  To set the tool tip generator for an XY plot’s item renderer, use the following method(defined in the AbstractXYItemRenderer class):
  public void setToolTipGenerator(
    XYToolTipGenerator generator);

Collecting Tool Tips
 
#设置tooltip generator是不够的
 
Tool tips are collected, along with other chart entity information, using the ChartRenderingInfo class. You need to supply an instance of this class to JFreeChart’s draw() method, otherwise no tool tip information will be recorded
  #自动处理
  Fortunately, the ChartPanel class takes care of this automatically, so if you are displaying your
charts using the ChartPanel class you do not need to worry about how tool tips are collected—it is
done for you.

Displaying Tool Tips
  #tooltip的显示同样由ChartPanel处理,可以设置是否显示它。
  Tool tips are automatically displayed by the ChartPanel class, provided that you have set up a tool tip generator for the plot (or the plot’s renderer).
  You can also enable or disable the display of tool tips in the ChartPanel class, using this method:
  public void setDisplayToolTips(boolean flag);

Disabling Tool Tips
  #取消tooltip的最佳方式。
  The most effective way to disable tool tips is to set the tool tip generator to null. This ensures that no tool tip information is even generated, which can save memory and processing time
 
Customising Tool Tips
  You can take full control of the text generated for each tool tip by providing your own implementation of the appropriate tool tip generator interface.



阅读(3259) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~