Reputation: 45
I have a requirement to have a stacked percentage column chart in highcharts display a breakdown of a specific percentage number rather than a breakdown of 100%. For example, if the number is 60%, the graph should show a breakdown of 60% (20% blue, 10% green, 30% yellow) rather than fill up to 100%. My understanding of percentage charts is they are always 100%, but wondering if this kind of manipulation is possible with highcharts somehow? Thanks.
Upvotes: 0
Views: 1844
Reputation: 235
Like what @Alden Be said, use stacked column with % labels. Here is the JSFiddle example.
$(function () {
$('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Stacked column chart'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
yAxis: {
min: 0,
title: {
text: 'Percentage'
},
labels: {
formatter: function () {
return this.value + '%';
}
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
},
formatter: function () {
return this.total + '%';
}
}
},
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: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
format:'{y}%',
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
style: {
textShadow: '0 0 3px black'
}
}
}
},
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]
}]
});
});
Upvotes: 0
Reputation: 517
Use Stacked column instead of stacked percentage column, then simply append a percent to your label. Percentage column automatically determines the percentages of all data points provided, it sounds like you want the column to instead simply render the provided information.
Upvotes: 0