VChart如何自定义Tooltip形状?

29 阅读1分钟

问题标题

VChart如何自定义Tooltip形状?

问题描述

Vchart的tooltip前面的形状有办法自定义吗?

解决方案

vchart的Spec中有tooltip相关的配置,配置tooltip属性即可。tooltip的mark属性表示hover到图元上的效果visactor.io/vchart/opti…

代码示例

const spec = {
  type: 'pie',
  data: [
    {
      id: 'id0',
      values: [
        { type: 'oxygen', value: '46.60' },
        { type: 'silicon', value: '27.72' },
        { type: 'aluminum', value: '8.13' },
        { type: 'iron', value: '5' },
        { type: 'calcium', value: '3.63' },
        { type: 'sodium', value: '2.83' },
        { type: 'potassium', value: '2.59' },
        { type: 'others', value: '3.5' }
      ]
    }
  ],
  tooltip: { 
    mark: 
    { 
      content: { 
        key: datum => datum['type'],
        value: datum => datum['value'] + '%',
        shapeType: 'square' 
      } 
    },
  },
  outerRadius: 0.8,
  valueField: 'value',
  categoryField: 'type',
  title: {
    visible: true,
    text: 'Statistics of Surface Element Content'
  },
  legends: {
    visible: true,
    orient: 'left'
  },
  label: {
    visible: true
  }
};

const vchart = new VChart(spec, { dom: CONTAINER_ID });
vchart.renderSync();

// Just for the convenience of console debugging, DO NOT COPY!
window['vchart'] = vchart;

结果展示

代码运行后,tooltip的symbol就变成了矩形

在线demo:codesandbox.io/p/sandbox/t…

相关文档