You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ApexCharts数据标签配置求助:如何展示数值而非百分比

在ApexCharts中设置数据标签显示具体数值而非百分比

要让数据标签显示原始具体数值,只需修改dataLabels中的formatter函数,直接从系列数据中获取原始值即可——部分图表类型(如饼图)中默认的val参数会返回百分比,因此需要主动获取定义好的原始数据。

修改后的dataLabels代码块

dataLabels: {
  enabled: true,
  textAnchor: "start",
  style: {
    colors: ["#fff"]
  },
  formatter: function(val, opt) {
    // 获取当前系列下的原始数据值
    const originalValue = opt.series[opt.seriesIndex][opt.dataPointIndex];
    return opt.w.globals.labels[opt.dataPointIndex] + ":  " + originalValue;
  },
  offsetX: 0,
  dropShadow: {
    enabled: true
  }
},

完整配置示例

var options = {
  series: [{
    name: 'Marine Sprite',
    data: [44, 55, 41, 37, 22, 43, 21]
  }, {
    name: 'Striking Calf',
    data: [53, 32, 33, 52, 13, 43, 32]
  }],
  dataLabels: {
    enabled: true,
    textAnchor: "start",
    style: {
      colors: ["#fff"]
    },
    formatter: function(val, opt) {
      const originalValue = opt.series[opt.seriesIndex][opt.dataPointIndex];
      return opt.w.globals.labels[opt.dataPointIndex] + ":  " + originalValue;
    },
    offsetX: 0,
    dropShadow: {
      enabled: true
    }
  }
};

修改完成后,数据标签会直接显示你定义在series.data中的具体数值,而非百分比。

内容的提问来源于stack exchange,提问作者user2902377

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 19:27:24