Hi , Can you please let me know how we can change the color for each group in a grouped bar chart. I am using plotly js.
Below is an example from documentation. Here i would like to change the color of the blue and orange group.
I can change the color of each bar for different values of x using markers:{color:} but not the group.
Kindly let me know if you need any other details.
Hi @rajkiran ,
try to use Plotly.restyle
for changing color every trace with different value in an existing plot.
var trace1 = {
x: ['giraffes', 'orangutans', 'monkeys'],
y: [20, 14, 23],
name: 'SF Zoo',
type: 'bar'
};
var trace2 = {
x: ['giraffes', 'orangutans', 'monkeys'],
y: [12, 18, 29],
name: 'LA Zoo',
type: 'bar'
};
var data = [trace1, trace2];
var layout = {barmode: 'group'};
Plotly.newPlot('myDiv', data, layout);
// restyle the first trace's marker color 'red' and the second's 'green'
var update = {
'marker.color': ['red', 'green']
};
Plotly.restyle('myDiv', update, [0, 1])
Thank you… this worked!!