VChart中如何定义label 显示的数值小数位数?

我使用VChart图表时,发现如果数字的小数位比较长时显示效果很不美观,有什么办法能控制标签显示的小数位长度吗?
ada5214a-6f76-47e3-a246-6b0197644e40.png

阅读 2.4k
2 个回答

解决方案 Solution

通过VChart的标签格式化函数可以解决这个问题,此外格式函数还可以支持自定义数字单位等需求

代码示例 Code Example

// two decimal places
spec.label.formatMethod = (value: number) => (+value).toFixed(2)

// numerical unit
spec.label.formatMethod = (value: number) => ((+value)/1e3).toFixed(2) + 'k'

结果展示 Results

image.png
Demo: https://codesandbox.io/s/label-formatter-d34xrm?file=/src/ind...

相关文档 Quote

formatMethod option:https://visactor.bytedance.net/vchart/option/barChart#label.f...

label tutorials: https://visactor.bytedance.net/vchart/guide/tutorial_docs/Cha...

github:https://github.com/VisActor/VChart

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题