VChart 图表标签格式化的方法有哪些?

296 阅读1分钟

问题描述

VChart 柱状图中,默认展示的是柱子对应数值的标签,我想展示类似 `x轴名称: y数值`这样的内容,有哪些办法可以自定义标签展示?

解决方案

有两种推荐的配置方式:

  1. 通过 label.formatMethod 配置格式化函数。

    1. 函数参数为(text: string | string[], datum?: any)text 为默认展示的文本,datum为图元数据。
    2. 函数返回值可以是一个字符串或字符串数组。其中,字符串数组会默认换行展示。
    3. 如果要配置为富文本,那么返回值则为富文本配置对象;
label: {
    formatMethod:(value, data) => `${data.name}: ${value}`
}

  1. 通过 label.formatter 配置模板字符串。
label: {
   formatter: `{name} : {value}`
}

相关文档

formatMethod demo: visactor.io/vchart/demo…

Formatter demo:visactor.io/vchart/demo…

相关配置项:visactor.io/vchart/opti…

github:github.com/VisActor/VC…