gpt4 book ai didi

javascript - 使用 Highcharts 自定义条形图文本

转载 作者:行者123 更新时间:2023-11-28 18:44:49 26 4
gpt4 key购买 nike

我正在创建一个堆叠的 Highcharts 条形图。在每个栏中,我想要有自定义文本。然而,highcharts 仅显示数据数量。

fiddle 是here .

我的代码是:

$(function () {
$('#container').highcharts({
chart: {
type: 'bar'
},
title: {
text: 'Stacked bar chart'
},
xAxis: {
categories: ['Apples', 'Oranges']
},
yAxis: {
min: 0,
title: {
text: 'Total fruit consumption'
}
},
legend: {
reversed: true
},
plotOptions: {
series: {
stacking: 'normal'
},
bar: {
dataLabels: {
enabled: true
}
}
},
series: [{
name: 'John',
data: [['test 1', 5], ['test 2', 3]]
}, {
name: 'Jane',
data: [['test 3', 2], ['test 4', 2]]
}]
});
});

我希望“测试 1”、“测试 2”等出现在条形图中(它们确实出现在弹出窗口上)。但相反,数据编号,即 5、3、2、ans 2,出现在那里。这可以吗?

最佳答案

See working fiddle with your data here

使用格式化函数:

 bar: {
dataLabels: {
formatter: function(){
return this.point.name
},
enabled: true
}
}

关于javascript - 使用 Highcharts 自定义条形图文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35551906/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com