Google Line Chart Adding Array of Objects

前端 未结 1 571
悲&欢浪女
悲&欢浪女 2021-01-26 06:45

I have an array of objects which I\'ve created by parsing a JSON string:

    var measurementData = @Html.Raw(JsonConvert.SerializeObject(this.Model.Item1));
             


        
相关标签:
1条回答
  • 2021-01-26 07:39

    You can use "setValue(rowIndex, columnIndex, value)" method:

    var jsonData = '[{"SlideId":"D2011", "InstrumentId":"I335", "IncMin":"37.13", "IncMax": "37.19", "BrMin":"31.4"}, {"SlideId":"D2014", "InstrumentId":"I335", "IncMin":"37.13", "IncMax": "37.19", "BrMin":"31.4"}]';
    
    var parsedData = JSON.parse(jsonData);
    var len = parsedData.length;
    
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'TimeStamp');
    data.addColumn('number', selectedMeasurements);
    
    data.addRows(len);
    
    for (var n = 0; n < len; n++) {
        var i=0;
        for (var key in parsedData[n]) {
            data.setValue(n, i, parsedData[n][key]);
            i++;
        }
    }
    
    chart.draw(data, options, {
            isStacked: true,
            vAxis: {
                viewWindowMode: 'explicit',
                viewWindow: {
                    max: 100,
                    min: 0
                }
            }
    });
    

    http://jsfiddle.net/mblenton/qnusuLtn/2/

    0 讨论(0)
提交回复
热议问题