使用for循环在CanvasJS中显示信息

时间:2018-04-17 14:07:32

标签: javascript canvasjs

我想使用CanvasJs的API信息。我已成功地在图表中显示信息,但我想让它变得动态。这就是我想要实现for循环的原因。

这是循环的代码:

var totalValue1 = parseInt('<%= Session["totalValue1"] %>'); 
var monthValue1 = parseInt('<%= Session["monthValue1"] %>'); 
var dateValue1 = '<%= Session["dateValue1"] %>';

var datapointsColumn = [];
for (var i = 0; i < totalValue1.length; i++) {
    datapoints.push({
        x: new Date(dateValue1[i].x),y:totalValue1[i].y
    })
}

var datapointsLine = [];
for (var i = 0; i < monthValue1.length; i++) {
    datapoints.push({
        x: new Date(dateValue1[i].x),y:monthValue1[i].y
    })
}

这是图表本身的代码:

data: [{
                    type: "column",
                    yValueFormatString: "€#",
                    showInLegend: true,
                    dataPoints: datapointsColumn
                }, {
                    type: "line",
                    showInLegend: true,
                    yValueFormatString: "€#",
                    dataPoints: datapointsLine
                }
                ]

0 个答案:

没有答案