3

So I am getting the error gd.data must be an array when I am attempting to add a trace to an existing graph with addTraces. The plotly is within an ajax call. I have tried explicitly declaring an array and adding the new trace data to it, and I have tried ensuring that the x and y coordinates are an array in same way. I am still getting the error gd.data must be an array. I saw that this was asked earlier, but did not have any answers. I was wondering if there was any solution to this issue, or if there was another way that I could add traces to an existing graph.

//adding the traces
let dd = [];
let pd = [];
dd.push(dateData);
pd.push(pricingData);
Plotly.addTraces('graphing-area', [{
    x: dd,
    y: pd,
    name: ticker,
    type: 'scatter',
    showlegend: true,
}]);
let trace = [{
    x: [dateData],
    y: [pricingData],
    name: ticker,
    type: 'scatter',
    showlegend: true
}];
let layout = {
    padding: {b:0},
    title: {
        text:'Bid Price vs Maturity',
        font: {
            family: 'Courier New, monospace',
            size: 18
        },
    }
};
Plotly.newPlot('graphing-area', trace, layout, {displayModeBar: false});

Does anybody have a solution or a workaround?

Thanks!

1
  • 1
    This error is going to occur when the chart you are trying to add traces to does not have a data array yet, i.e. you first called Plotly.newPlot(graphDiv, null, layout) before adding the trace. Commented Nov 20, 2019 at 12:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.