javascript - Highcharts 标签显示值而不是名称

标签 javascript highcharts

我有一个带有 Highcharts 的饼图

plotOptions: {
          pie: {
              allowPointSelect: true,
              cursor: 'pointer',
              dataLabels: {
                  enabled: true,
                   distance: -30
              },
              showInLegend: true
          }
      },
      series: [{
          name: 'Types',
          colorByPoint: true,
          data: [ {
              name: 'Debtors',
              y: 10.38
          }, {
              name: 'Suppliers',
              y: 4.77
          },
        ]
      }]

当前饼图中标签中的数据名称(即:债务人、 vendor )就是饼图中显示的内容

我希望显示值,但图例应保留名称。

最佳答案

您需要启用该格式。

plotOptions: {
          pie: {
              allowPointSelect: true,
              cursor: 'pointer',
              dataLabels: {
                  enabled: true,
                   distance: -30,
                   format: '<b>{point.name}</b>: {point.y:,.2f}',
              },
              showInLegend: true
          }  
    },
    series: [{
          name: 'Types',
          colorByPoint: true,
          data: [ {
              name: 'Debtors',
              y: 10.38
          }, {
              name: 'Suppliers',
              y: 4.77
          },
        ]
      }]

Jsfiddle 演示:http://jsfiddle.net/powrcnf1/

关于javascript - Highcharts 标签显示值而不是名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45824522/

相关文章:

javascript - 如果用户空闲,我如何编写一个 javascript 函数每隔几秒在 html 网页上的选项卡之间移动

javascript - 检查单选按钮是否存在 jQuery

javascript - 使用 NextJS 和 highcharts-react-official 的气泡图

javascript - 栏上的背景未从 Highcharts 中删除

javascript - Highcharts:如何将 y 轴移至中心(例如按性别和年龄组划分的人口)

javascript - ES6 类中的 jQuery 触发器不起作用

javascript - 如何防止窗口大小调整影响您的元素

javascript - 如何在forEach内部调用promise?

javascript - Highcharts 条形图将数据标签格式化为百分比并添加文本

javascript - Highcharts - 重绘空图表