Reputation: 2784
As the question states, I want to give different color to each stack in the stacked bar chart.
I have tried:
Setting colorByPoint=true
in pie
options, which sets different color to each bar.
Setting color
to each JSON
in series
, which doesn't work as expected.
But as shown in picture, I want different color for each stack.
Upvotes: 1
Views: 3269
Reputation: 3732
You can set color for whole series points, or just for one point. There is no other way out, so in order to achieve the effect which is showed on your image, you need to set the different color on every point inside of your series, and then make this color a bit brighter on next series definition.
Highcharts.chart('container', {
chart: {
type: 'column'
},
title: {
text: 'Stacked column chart'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears']
},
plotOptions: {
series: {
stacking: 'normal'
}
},
legend: false,
series: [{
name: 'Jane',
data: [{
y: 2,
color: '#ff0000' // red
}, {
y: 3,
color: '#00ff00' // green
}, {
y: 1,
color: '#0000ff' // blue
}]
}, {
name: 'Joe',
data: [{
y: 1,
color: '#990000' // medium red
}, {
y: 2,
color: '#009900' // medium green
}, {
y: 3,
color: '#000099' // medium blue
}]
}, {
name: 'John',
data: [{
y: 3,
color: '#550000' // dark red
}, {
y: 1,
color: '#005500' // dark green
}, {
y: 2,
color: '#000055' // dark blue
}]
}]
});
Live example: https://jsfiddle.net/vyamk5cg/
Upvotes: 1
Reputation: 15639
Use the color
property to set it.
series: [{
name: 'Top',
data: [
{y:15, color:'blue'},
{y:64, color:'red'},
{y:27, color:'green'},
{y:32, color:'yellow'},
{y:17, color:'purple'}
]
}.............
Hope this helps!
Upvotes: 0