gpt4 book ai didi

javascript - canvasJS 通过直接传递一个对象来插入新的数据点

转载 作者:行者123 更新时间:2023-11-30 21:01:47 24 4
gpt4 key购买 nike

所以,

我得到一个对象,其中包含我想以这种形式(通过 Json)以下列形式绘制的数据:

chartData(GraphData.year, GraphData.month, GraphData.day, GraphData.hour, GraphData.minute, GraphData.y, GraphData.indexLabel, GraphData.markerColor, GraphData.markerType))

所以基本上我有:

chartData{year:2017, month:11, day:2, hour:10, y: 21 , indexLabel: "Pump 1 On", markerColor: "green", markerType: "triangle" }

但是 canvasJS 需要它们像这样:

chartData{ x: new Date(1987,03,25, 08, 39), y: 658 , indexLabel: "Pump 1 On", markerColor: "green", markerType: "triangle" }

如何将我的对象转换为所需的形式?简而言之,chartData 类的构造函数应该是什么样的?另外我想在一个数组中添加多个 theese 对象,比如

dailyGraphData.push(new chartData);

(当然我会在将 chartData 对象插入 dailyGraphData 数组之前更新它)

提前联系!

最佳答案

好的,以备后用

class chartTempData {
constructor(year, month, day, hour, minute, levelCM, indexLabel, markerColor, markerType) {
this.year = year;
this.month = month;
this.day = day;
this.hour = hour;
this.minute = minute;
this.levelCM = levelCM;
this.indexLabel = indexLabel;
this.markerColor = markerColor;
this.markerType = markerType;
}
}



class chartData {
constructor(date, y, indexLabel, markerColor, markerType) {
this.x = date;
this.y = y;
this.indexLabel = indexLabel;
this.markerColor = markerColor;
this.markerType = markerType;
}
}


var dailyGraphData = new Array();
//The following line is just for test purpuse, normaly these values are asigned by incomming JSON data
var dailyTempGraphData = new chartTempData(2017, 11, 2, 08, 13, 25, "Pump 1 On", "green", "triangle"); //incomming data is firstly stored here element by element then stored in the regular array en mase




function transferDataToArray()
{
var dailyGraphDataArrayLength=0;
dailyGraphDataArrayLength = dailyGraphData.push(new chartData(new Date(dailyTempGraphData.year, dailyTempGraphData.month, dailyTempGraphData.day, dailyTempGraphData.hour, dailyTempGraphData.minute), dailyTempGraphData.levelCM, dailyTempGraphData.indexLabel, dailyTempGraphData.markerColor, dailyTempGraphData.markerType));
dailyGraphDataArrayLength = dailyGraphData.push(new chartData(new Date(dailyTempGraphData.year, dailyTempGraphData.month, dailyTempGraphData.day, dailyTempGraphData.hour+2, dailyTempGraphData.minute+15), dailyTempGraphData.levelCM+14, "Hollo worls", "purple", "cross"));
console.log(dailyGraphDataArrayLength);
console.log(dailyGraphData[0]);
console.log(dailyTempGraphData);
chart.render();

}

关于javascript - canvasJS 通过直接传递一个对象来插入新的数据点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47072183/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com