tooltip
Previous
title
Next
contrastReverse
Loading...
提示(Tooltip)可以提供关于数据点的额外信息,帮助用户更好地理解和解释可视化。
const config = {tooltip: {title: 'Date',items: [{ channel: 'y' }],}}
属性 | 描述 | 类型 | 默认值 |
---|---|---|---|
title | 标题,支持一段文本或 innerHTML 字符串 | TooltipItem | - |
items | 定义每一个提示项的配置 | TooltipItem | - |
type TooltipItem =| string| false| {name?: string;color?: string;channel?: string;field?: string;value?: string;// 格式化 tooltip item 的值(支持 d3-format 对应的字符串)valueFormatter?: string | ((d: any) => string);};
const config = {tooltip: {title: (d) => (d.value > 100 ? d.name : d.age), // transform}}
// 单个字段const config = {tooltip: {field: 'a'}}// 单个通道const config = {tooltip: {channel: 'y'}}// 格式化const config = {tooltip: { channel: 'y', valueFormatter: (d) => d.toFixed(1) }}// d3-format 支持的字符// https://github.com/d3/d3-formatconst config = {tooltip: { channel: 'y', valueFormatter: '~s' }}// 完整信息const config = {tooltip: { name: 'name', color: 'red', value: 'color' }}// 回调const config = {tooltip: (d, // 每一个数据项index, // 索引data, // 完整数据column, // 通道) => ({value: `${column.y.value[index]} - ${column.y1.value[index]}`,})}// 多个 itemconst config = {tooltip: { items: [{ channel: 'y' }, { channel: 'x' }] }}
const config = {tooltip: {title: 'a',items: [{ channel: 'x' }, { channel: 'y' }],}}