1
在legendItemClick上,如何防止從總數中減去圖例項目值,而是將該值添加到另一個圖例項目。Highcharts堆積柱形圖更改legendItemClick函數
E.g.我希望「其他水果」系列包含所有關閉的水果系列(與「其他蔬菜」系列相同)。
這裏是Fiddle
$(function() {
$('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Stacked column chart'
},
xAxis: {
categories: ['Then', 'Now']
},
yAxis: {
min: 0,
title: {
text: 'Total 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: {
headerFormat: '<b>{point.x}</b><br/>',
pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
},
plotOptions: {
series: {
events: {
legendItemClick: function() {
//if fruit/veg is clicked then add value to other fruit/veg and keep the total unchanged
// return false;
}
}
},
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
formatter:function() {
return this.series.name+' '+this.point.y;
},
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
style: {
textShadow: '0 0 3px black'
}
}
}
},
series: [{
name: 'Other Fruit',
data: [8, 13]
},{
name: 'Other Veg',
data: [16, 10]
},{
name: 'Tomatoes',
data: [3, 7]
},{
name: 'Cucumbers',
data: [5, 4]
},{
name: 'Apples',
data: [5, 3]
}, {
name: 'Bananas',
data: [3, 6]
}, {
name: 'Oranges',
data: [3, 4]
}]
});
});