2016-09-30 197 views
0

我創建了一個條形圖,以我想要的方式正常工作。現在,我試圖添加一個線條圖來重疊條,但是當我運行代碼時,線條圖會出現,但條形圖會消失。添加linegraph看起來很簡單,但由於某種原因,它不起作用。我在控制檯中也沒有遇到任何錯誤。Plotly.js將條形圖添加到條形圖使條形消失

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); 

回答

0

哦壩,我TRACE1戴着牙套+周圍的值,這工作了僅在酒吧花括號,但使它dissappear的linegraph調用時。