TypeError: Cannot read property 'map' of undefined

Hi, I’m new in Javascript and Plotly. I’m have no idea how to solve the error message [TypeError: Cannot read property ‘map’ of undefined]. I’m plotting a scatter plot with 2 sets of input data. I try to update the data setting and the error message is prompt for the last line of the code as shown below:

trace1 = {
x: xdata,
y: ydata,
mode: ‘markers’,
type: ‘scatter’,
text: cdata,
marker: {size: 20}
}
if (!isNaN(cdata[1])){
var update = {
marker: {color: cdata}
};
Plotly.restyle(‘view’, update);
}
else {
var update = {
transforms: [{type: “groupby”, groups: cdata}]
};
Plotly.restyle(‘view’, update);
}

Any help would be greatly appreciated.

Wrapping your data arrays into an additional set of [ ] should do the trick:

For example, try

var update = {
  marker: {color: [cdata]}
};

and

var update = {
  transforms: [{type: “groupby”, groups: [cdata]}]
};

See https://plot.ly/javascript/plotlyjs-function-reference/#plotlyrestyle for more on Plotly.restyle.