1

I am trying to use PLOTLY.JS to plot 2 line graphs. But nothing is showing up on the screen except an empty graph. Any help? It works fine with one lines, bar charts, etc.

var plot_data = {}
var trace1 = {
    x: [4, 3, 1],
    y: [1, 3, 6],mode: 'lines',
    type: 'scatter'
  };

var trace2 = {
    x: [6, 8, 9],
    y: [1, 2, 4],mode: 'lines',
    type: 'scatter'
};

var data = [trace1, trace2];
plot_data.push(data);
var layout = 
{
  title: { text: 'Task Plot', font: { family: 'Courier New, monospace', size: 24 }, xref: 'paper', x: 0.05,}
};

//var config = {responsive : true};
Tester = document.getElementById('myDash');

Plotly.newPlot(Tester, plot_data, layout);
3
  • What if you try Plotly.newPlot(Tester, data, layout); Commented Jul 10, 2022 at 0:13
  • 1
    Dude!! You we're right. Thank you so much, kinda feel bad I didn't try something like that haha! Well done. Thank you. It worked when I made that change. @DerekO Commented Jul 10, 2022 at 2:03
  • 1
    glad i could help! i'm going to post my comment as an answer with a bit of an explanation – that way if anyone has the same question, they can find the answer more easily :) Commented Jul 10, 2022 at 16:00

1 Answer 1

1

If you look at the documentation here, you'll want to pass an array of traces to Plotly.newPlot, so you can replace plot_data with data:

Plotly.newPlot(Tester, data, layout);
Sign up to request clarification or add additional context in comments.

Comments

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.