Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 绘制错误的canvas.js时间序列(从12月到1月)_Html_Canvas_Plot_Time Series - Fatal编程技术网

Html 绘制错误的canvas.js时间序列(从12月到1月)

Html 绘制错误的canvas.js时间序列(从12月到1月),html,canvas,plot,time-series,Html,Canvas,Plot,Time Series,正如您所见,我正在绘制KVA与时间的折线图(canvas.js),问题是数据绘制时间为2019年1月14日至2018年2月13日,但实际数据属于2018年12月14日至2019年1月14日。不确定这是canvas.js中的错误还是我做错了什么。如何修复 var options = { zoomEnabled: true, animationEnabled: true, title: { text: selectedText }, axisX

正如您所见,我正在绘制KVA与时间的折线图(canvas.js),问题是数据绘制时间为2019年1月14日至2018年2月13日,但实际数据属于2018年12月14日至2019年1月14日。不确定这是canvas.js中的错误还是我做错了什么。如何修复

var options = {
    zoomEnabled: true,
    animationEnabled: true,
    title: {
        text: selectedText
    },
    axisX:{
        title: "Timeline",
        gridThickness: 1
    },
    axisY: {
        title: "KVA",
        includeZero: false,
        lineThickness: 1

    },
    data: [{
        type: "line",
        dataPoints:dataPoints
        }]  // random data
};
我的数据点看起来像这样

dataPoints.push({ x: new Date(2018,12,13,06,09,38), y: 384 }); 
dataPoints.push({ x: new Date(2018,12,13,06,12,46), y: 386 }); 
dataPoints.push({ x: new Date(2018,12,13,06,15,53), y: 379 }); 
dataPoints.push({ x: new Date(2018,12,13,06,19,02), y: 377 });
....
....
dataPoints.push({ x: new Date(2019,01,11,17,11,12), y: 632 }); 
dataPoints.push({ x: new Date(2019,01,11,17,13,35), y: 616 }); 
dataPoints.push({ x: new Date(2019,01,11,17,15,49), y: 614 });
如何修复?
我的错,这个月应该从0指数开始,而不是从1指数开始。正确的代码是

while($row = mysqli_fetch_array($result)){

           $str = str_replace(array(":"," "),"-", $row['datetime']);
           $t = explode("-", $str);
           $month = $t[1]-1;

           echo 'dataPoints.push({
                        x: new Date('.$t[0].','.$month.','.$t[2].','.$t[3].','.$t[4].'),
                        y: '.$row['KVA'].'
                    });';
                }
也就是说,必须从SQL月数中减去1,使其成为0索引,JavaScript Date()才能正常工作