简体   繁体   English

Plotly.js将线图添加到条形图中使条消失

[英]Plotly.js adding linegraph to barchart makes bars disappear

I have created a barchart that works properly the way I want. 我创建了一个可以按照我想要的方式正常工作的条形图。 Right now, I'm trying to add a linegraph to overlap the bars, but when I run the code, the linegraph appears, but the bars disappear. 现在,我试图添加一个折线图以重叠条形图,但是当我运行代码时,线形图出现了,但是条形图消失了。 It seems pretty simple to add the linegraph, but for some reason it's not working. 添加线图似乎很简单,但是由于某些原因,它不起作用。 I'm not getting any mistakes in console either. 我在控制台上也没有遇到任何错误。

var x_text = ["Comodities","Consumer Discretionary","Utilities",
              "Health & Biotech","Global Real Estate","Financials",
              "Emerging Market Bonds","Technologies","Industrials",
              "Oil & Gas","China Equities","S&P500"];
  //             
  var trace1 = [{ 

    x: x_text, // X axis (names)
    y: zValues, // Values (y axis)
    hoverinfo: zValues, 
    type: 'bar',
    orientation:"v",
    marker: {
    color: color_list, // Color of bars
    line: {
      color: 'rbg(8,48,107)',
      width: 1
    }},
    yauto: false,
    showscale: true,
  }];

  var trace2 = {
  x: x_text,
  y: [-0.1,-0.1,2.3,3.3,1.0,0.4,0.9,3.0,-0.1,-1.4,3.0,0.2],
  mode: 'lines',
  line:{
    color:'black'
  },
  type: 'scatter'
};


  var layout = {
    font:{
      // Text size and color
      size:16,
      family:'helvetica',
      color: "white"
    },
    annotations: arrow(),
    xaxis:  {
      side: 'bottom',
      orientation: "right"
    },
    yaxis: {
      autosize: true,
      tickfont: "white",
      ticksuffix: "%",
      // Y axis scale
      autorange: false,
      range :[-20,20]
    },
    // Graph position
    margin: {
    l: 90,
    r: 90,
    b: 120,
    t: 20,
    pad: 10
  },
    // Graph background colors
    paper_bgcolor: "transparent", 
    plot_bgcolor:"transparent", 
  };

var data = [trace1, trace2];

Plotly.newPlot('myDiv',data,layout);

哦,该死,我的trace1的值周围有花括号+弯括号,这仅适用于条形图,但在调用线图时消失了。

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

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