dyGraphs Second Y Axis not being displayed when using a variable as 'y2'

前端 未结 1 1589
名媛妹妹
名媛妹妹 2021-01-26 00:19

I have the following code to display a graph with two axes. The data is of the form: Date, Value1, Value2

var sg = new Dygraph(document.getElemantBy         


        
相关标签:
1条回答
  • 2021-01-26 00:49

    This is a basic JavaScript issue. When string2 appears as a key in an object literal, it means the string "string2", not the value of the string2 variable. You need to create an options object and fill it out in pieces, like so:

    var opts = {
        labels: ['Date', string1, string2],
        legend: 'always',
        series: {},
        ylabel: string1,
        y2label: string2
    };
    opts.series[string2] = { axis: 'y2' };
    
    var sg = new Dygraph(document.getElemantById("div"), lGraphData, opts);
    
    0 讨论(0)
提交回复
热议问题