简体   繁体   English

绘制折线图-多条线

[英]Plotly line chart - multiple lines

I want to create a line chart with three lines (male,female,unknown). 我想创建一个包含三行(男性,女性,未知)的折线图。 This is a sample of my data: 这是我的数据样本:

timestamp;sex;number
06:00;male;5
07:00;male;2
07:00;unkown;3
07:00;female;4
09:00;female;4

Is there a option in plotly to automatically create the three lines or do I need to loop through the data and create three traces by myself? 是否有选择地自动创建三条线?或者我需要遍历数据并自己创建三条迹线? This is my code so far: 到目前为止,这是我的代码:

var trace1 = {
  type: 'scatter',
  x: x,
  y: y,
  name: "Male",
  transforms: [{
    type: 'aggregate',
    groups: x,
    aggregations: [
      {target: 'y', func: 'count', enabled: true},
    ]
  }]
};


var data = [trace1];

Plotly.newPlot('myDiv', data, {title: 'Plotting CSV data from AJAX call'});

You need to create different data set(trace) for each category. 您需要为每个类别创建不同的数据集(跟踪)。
Maybe this can help you. 也许可以帮助您。

var men = {
  x: x, 
  y: y, 
  type: 'scatter',
  name:'male'
};

var female = {
  x: x, 
  y: y, 
  type: 'scatter',
  'name':'female'
};
var unknown = {
  x: x, 
  y:y, 
  type: 'scatter',
  'name':'unknown'
};

var data = [men, female,unknown];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM