How does update method work

var trace1 = {
x: [1, 2, 3],
y: [1, 2, 3],
type: ‘scatter’,
};

var data = [trace1];

Plotly.newPlot(graph2, data, {});

var update = {
x: [2,4,6],
‘marker.color’: ‘red’
};

Plotly.restyle(graph2, update);
console.log(graph2.data);

The log is shown below where only the first value of x is update not the whole array of value.

plotly_log

I want to update the whole trace or say just the x-value. I tried above code but can’t see it working properly. I can see marker color updated properly but not data. What am i missing ?

Thanks.

https://plot.ly/javascript/plotlyjs-function-reference/#plotlyupdate is a good place to start.

In your case, something like:

var trace1 = {
  x: [1, 2, 3],
  y: [1, 2, 3],
  type: 'scatter',
};

var data = [trace1];

Plotly.newPlot(graph2, data, {});

var update = {
  x: [[2,4,6]],
  'marker.color': 'red'
};

Plotly.restyle(graph2, update);

should work as expected.

Thanks… It works. I should have known :slight_smile:

1 Like

Alright, I have a scattergl what have many subplots, and I want to give color scale when restyle subplots. My code is:
const data= {
x: [[1,2,3],[2,8,10]],
marker: {
size: 3,
cmin:0,
cmax:1,
color:[?],
colorscale:‘Greens’
},
};
let echoDataIndexArray = [1,4]
Plotly.restyle(mydiv, echoData, echoDataIndexArray);

But color is not showing:( Thanks.