Tooltip

How to Register Tooltip Plugin
F2 has modular structure provides best tree-shaking results and package size optimization.
If you just import F2 from '@antv/f2', then it has included tooltip by default. But if you want a better package size optimization, you can register manually:
Tooltip Configuration
Close Tooltip
If you call chart.tooltip(false), tooltip will not be rendered.
Configure Tooltip
Below is the method for configuring tooltip, the detail properties can be found in table.
Name
Type
Default
Description
alwaysShow
Boolean
false
Whether the tooltip is still show when the touch area is not in the chart.It can be set to be true to preserve displaying.
offsetX
Number
0
Tooltip offset in x direction.
offsetY
Number
0
Tooltip offset in y direction.
triggerOn
String / Array
[ 'touchstart', 'touchmove' ]
The event that will trigger tooltip.
triggerOff
String / Array
'touchend'
The event that will hide tooltip.
showTitle
Boolean
false
Wether to show the title.
showCrosshairs
Boolean
Wether to show the tooltip crosshairs. The default value of different charts is different, point, line, area and path will show by default.
crosshairsStyle
Object
Style of the crosshairs line, default setting is:
{
stroke: 'rgba(0, 0, 0, 0.25)',
lineWidth: 2
}
showTooltipMarker
Boolean
true
Wether to display tooltipMarker.
tooltipMarkerStyle
Object
Style of the tooltipMarker.
background
Object
The background style of tooltip content box.
titleStyle
Object
Style for tooltip's title, invalid if showTitle is false.
nameStyle
Object
Style for each tooltip item's name part.
valueStyle
Object
Style for each tooltip item's value part.
showItemMarker
Boolean
true
Wether to show the each tooltip item's marker.
itemMarkerStyle
Object
Style for each tooltip item's marker.
Tooltip Item Interface
The picture below shows the structure of tooltip content, it includes title and a group of items, each item consists of marker, name and value.

The tooltip items passed to the tooltip onShow , onChange, onHide callbacks implement the following interface:
onShow callback
onShow callbackWe can use onShow callback to change the tooltip's show content. It will trigger when the tooltip is shown.
As following example, we will change the value of name to the value of title, see demo and code here.
onChange callback
onChange callbackIt will trigger when the tooltip's content changed. Usually combined with the custom attribute for custom tooltip.
onHide callback
onHide callbackIt will trigger when the tooltip is disappeared.
Custom Tooltip
Custom tooltips allow you to hook into the tooltip rendering process so that you can render the tooltip in your own custom way. Generally this is used to create an HTML tooltip instead of an canvas one or combined with legend.
Combine Legend and Tooltip
On mobile, in order to make better use of the screen size, the tooltip and legend are often combined in the chart design. Like this:

In F2, we can use a custom tooltip to implement, see demo and code here:
External(HTML) Tooltip
We also can define a html tooltip, like this, see demo and code here:

Or Like this, combine with Guide.Html and Tooltip, see demo and code here:

More Demos
Last updated




