Highcharts 柱形图:在柱形上显示数字和百分比 - 完整指南
"Highcharts 柱形图:在柱形上显示数字和百分比 - 完整指南" 在 Highcharts 中,要同时显示柱形上的数字和百分比,可以使用 formatter 函数来自定义柱形上的标签。下面是一个示例代码: \n\njavascript\nHighcharts.chart('container', {\n chart: {\n type: 'column'\n },\n title: {\n text: '柱形图示例'\n },\n xAxis: {\n categories: ['A', 'B', 'C', 'D', 'E']\n },\n yAxis: {\n title: {\n text: '值'\n }\n },\n series: [{\n name: '数据',\n data: [10, 20, 30, 40, 50],\n dataLabels: {\n enabled: true,\n formatter: function() {\n var percentage = (this.y / this.total * 100).toFixed(1);\n return this.y + ' (' + percentage + '%)';\n }\n }\n }]\n});\n\n\n在上面的代码中,dataLabels 选项用于设置数据标签的样式和内容。enabled 设置为 true 表示启用数据标签。formatter 函数用于自定义数据标签的显示内容。在函数中,this.y 表示柱形的值,this.total 表示所有柱形的总值。使用这两个值可以计算出百分比,并将其与柱形的值一起显示在柱形上。\n\n通过修改 formatter 函数中的代码,你可以根据需要自定义数据标签的显示格式。
原文地址: https://www.cveoy.top/t/topic/p2TA 著作权归作者所有。请勿转载和采集!