问题标题
VChart饼图标签如何自定义?
问题描述
vchart饼图标签能够自定义吗?我希望自定义饼图的标签内容,把数值加上去
解决方案
饼图的标签配置在label字段中: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' }
]
}
],
outerRadius: 0.8,
valueField: 'value',
categoryField: 'type',
title: {
visible: true,
text: 'Statistics of Surface Element Content'
},
legends: {
visible: true,
orient: 'left'
},
label: {
visible: true,
formatMethod: (text, datum) => {
return `${text}: ${datum.value}`
}
},
tooltip: {
mark: {
content: [
{
key: datum => datum['type'],
value: datum => datum['value'] + '%'
}
]
}
}
};
const vchart = new VChart(spec, { dom: CONTAINER_ID });
vchart.renderSync();
// Just for the convenience of console debugging, DO NOT COPY!
window['vchart'] = vchart;
结果展示
代码运行后,标签就可以格式化了
在线demo:codesandbox.io/p/sandbox/p…
相关文档
- VChart 的官网:visactor.io/vchart/
- formatMethod文档:visactor.io/vchart/opti…
- VChart github:github.com/VisActor/VC…