要将柱形图柱形上的数字转换成百分比,你可以使用Highcharts的formatter函数来自定义数据标签显示的格式。

这里是一个示例代码,将柱形上的数字转换为百分比显示:

Highcharts.chart('container', {
  chart: {
    type: 'column'
  },
  title: {
    text: '柱形图'
  },
  xAxis: {
    categories: ['A', 'B', 'C']
  },
  yAxis: {
    title: {
      text: '百分比'
    },
    labels: {
      formatter: function() {
        return this.value + '%';
      }
    }
  },
  series: [{
    name: '数据',
    data: [0.1, 0.2, 0.3],
    dataLabels: {
      enabled: true,
      formatter: function() {
        return (this.y * 100).toFixed(2) + '%';
      }
    }
  }]
});

在上述代码中,通过设置yAxis.labels.formatter函数来将Y轴刻度上的数字转换成百分比显示。同时,通过设置series.dataLabels.formatter函数来将柱形上的数字转换成百分比显示。

formatter函数中,使用this.value来表示刻度上的值,使用this.y来表示柱形上的值。将this.y乘以100并使用toFixed(2)方法来保留两位小数,然后添加%符号即可将数字转换为百分比

highcharts柱形图柱形上显示数字如何转换成百分比

原文地址: https://www.cveoy.top/t/topic/ikUt 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录