Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple time series lines in Plotly.js

I am hoping to use plot.ly to graph multiple time series lines.

I am using the following code:

var trace1 = [
  {
    x: ['2013-10-04 22:23:00', '2013-11-04 22:23:00', '2013-12-04 22:23:00'],
    y: [1, 3, 6],mode: 'lines',
    type: 'scatter'
  }
];

var trace2 = [
  {
    x: ['2013-10-04 22:23:00', '2013-11-04 22:23:00', '2013-12-04 22:23:00'],
    y: [1, 2, 4],mode: 'lines',
    type: 'scatter'
  }
];

var data = [trace1, trace2];


Plotly.newPlot('myDiv', data);

But nothing appears. Does anyone know if it is possible to make them with Plotly.js?

like image 226
Union find Avatar asked Sep 01 '25 02:09

Union find


1 Answers

plotly traces need to be objects not arrays. This should work:

var trace1 = {
    x: ['2013-10-04 22:23:00', '2013-11-04 22:23:00', '2013-12-04 22:23:00'],
    y: [1, 3, 6],mode: 'lines',
    type: 'scatter'
  };

var trace2 = {
    x: ['2013-10-04 22:23:00', '2013-11-04 22:23:00', '2013-12-04 22:23:00'],
    y: [1, 2, 4],mode: 'lines',
    type: 'scatter'
};

var data = [trace1, trace2];


Plotly.newPlot('myDiv', data);
like image 76
etpinard Avatar answered Sep 02 '25 22:09

etpinard