gpt4 book ai didi

javascript - 当类别的所有条形值等于 0 时,Highcharts 条形图删除类别

转载 作者:行者123 更新时间:2023-12-02 18:51:06 26 4
gpt4 key购买 nike

当某个类别的所有条形值都等于 0 时,如何删除该类别

参见:( http://jsfiddle.net/no1uknow/EJFsH/1/ )

如果只有一个栏等于 0,则不应删除该栏。但如果所有 3 个条都等于 0,则应删除该类别。

chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column'
},
title: {
text: 'Stacked column chart'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
yAxis: {
min: 0,
title: {
text: 'Total fruit consumption'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'blue'
}
}
},
legend: {
align: 'right',
x: -100,
verticalAlign: 'top',
y: 20,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'gray',
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'
}
}
},
series: [{
name: 'John',
data: [5, 3, 4, 7, 2]
}, {
name: 'Jane',
data: [2, 2, 3, 2, 1]
}, {
name: 'Joe',
data: [3, 4, 4, 2, 5]
}]
});
});

最佳答案

您需要在初始化图表之前过滤数据,如下所示:

var data = [{
name: 'Year 1800',
data: [0, 0, 0, 0, 0]
}, {
name: 'Year 1900',
data: [0, 156, 947, 408, 6]
}, {
name: 'Year 2008',
data: [0, 914, 4054, 732, 34]
}];

data = $.grep(data, function (category) {
return $.grep(category.data, function (item) {
return item > 0;
}).length > 0;
});

http://jsfiddle.net/EJFsH/2/

关于javascript - 当类别的所有条形值等于 0 时,Highcharts 条形图删除类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15815723/

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