Hi,
I’m relatively new to plotly js and can’t get around this error when using .addTraces().
I have an existing scatter plot in ‘myDiv’, and I want to add a few traces. I’ve defined the traces like this:
var trace3 = {
type: "scatter",
mode: "lines",
name: "F1",
x: dateArray1,
y: priceArray1,
visible: "legendonly",
line: { color: '#FF5050' },
connectgaps: true,
marker: {
size: 5,
}
};
var trace4 = {
type: "scatter",
mode: "lines",
name: "F2",
x: dateArray2,
y: priceArray2,
visible: "legendonly",
line: { color: '#3399FF' },
connectgaps: true,
marker: {
size: 5,
}
};
var trace5 = {
type: "scatter",
mode: "lines",
name: "F3",
x: dateArray3,
y: priceArray3,
visible: "legendonly",
line: { color: '#4dffa6' },
connectgaps: true,
marker: {
size: 5,
}
};
var trace6 = {
type: "scatter",
mode: "lines",
name: "F4",
x: dateArray4,
y: priceArray4,
visible: "legendonly",
line: { color: '#7070db' },
connectgaps: true,
marker: {
size: 5,
}
};
Then I set var data = [trace3, trace4, trace5, trace6]
When I call Plotly.addTraces(‘myDiv’, data); I get the error ‘gd.data must be an array’. However, maybe one out of every five times, the traces are added without an error.
I’ve tried initializing data as [], then pushing the traces and it doesn’t work. I’ve tried just typing the traces directly into an array in the .addTraces call, doesn’t work. I’ve tried setting the array equal to the first element of each trace [trace3[0], trace4[0]] and it still didn’t work. What am I missing?