gpt4 book ai didi

javascript - HighChart Stacked Column 标签问题

转载 作者:行者123 更新时间:2023-11-30 17:03:16 26 4
gpt4 key购买 nike

我有一个图表,其中的值不均匀,即:第一个值为 1315,第二个值为 1,依此类推,显示图表时标签重叠。我已经在多个论坛中搜索过,但没有人遇到完全相同的问题。这是查看问题的 fiddle :http://jsfiddle.net/6LutjLc3/

$(function () {
$('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Stacked column chart'
},
xAxis: {
categories: ['Issue']
},
yAxis: {
min: 0,
title: {
text: 'Total fruit consumption'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
}
}
},
legend: {
align: 'right',
x: -30,
verticalAlign: 'top',
y: 25,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
formatter: function () {
return '<b>' + this.x + '</b><br/>' +
this.series.name + ': ' + this.y + '<br/>' +
'Total: ' + this.point.stackTotal;
}
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
style: {
textShadow: '0 0 3px black'
}
}
}
},
series: [{
name: 'John',
data: [1235]
}, {
name: 'Toto',
data: [2]
}, {
name: 'Matt',
data: [1]
}, {
name: 'Jane',
data: [72]
}, {
name: 'Joe',
data: [3]
}]
});

});

我需要编写的代码是为值 1 提供一个框,就像 highchart 中的任何其他示例一样,标签适合该框。

预先感谢您的帮助!

最佳答案

如果您的客户要求使用这种样式的图表,您可以通过修改数据标签设置来获得更好看的结果。将 overflow 设置为 false 并添加一个格式化程序函数,如果它至少返回当前总数的 7%(或任何最适合您的百分比),则该函数将有所帮助。请参阅以下内容:

dataLabels: {
enabled: true,
overflow: false,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
style: {
textShadow: '0 0 3px black'
},
formatter: function () {
if (this.percentage >= 7) return this.y;
}
}

在这里 fiddle :http://jsfiddle.net/6LutjLc3/4/

关于javascript - HighChart Stacked Column 标签问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28483406/

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