【发布时间】:2023-02-10 12:44:22
【问题描述】:
我有这样的数据:
{
"measurements": [
{
"id": 10,
"key": "Demoo",
"value": "00:00:03.733;",
"date": "2023-02-08",
"time": "11:05",
"value_time_formatted": "00:00:03.733"
},
{
"id": 11,
"key": "Demooo 2",
"value": "00:00:05.191;",
"date": "2023-02-08",
"time": "11:31",
"value_time_formatted": "00:00:05.191"
},
{
"id": 12,
"key": "Demo 22",
"value": "00:00:03.002;",
"date": "2023-02-08",
"time": "11:31",
"value_time_formatted": "00:00:03.002"
}
]}
当我尝试从日期作为标签和 value_time_formatted 作为值制作折线图时,我收到此错误:
ERROR TypeError: Cannot create property 'data' on string '00:00:03.733'
绑定图表值的代码如下所示:
this.lineBarLabels = [];
this.lineBarValue = [];
res.measurements.forEach(element => {
this.lineBarLabels.push(element.date);
this.lineBarValue.push(element.value_time_formatted);
});
this.lineBar = new Chart(this.linePresents.nativeElement, {
type: 'line',
data: {
labels: this.lineBarLabels,
datasets: this.lineBarValue
}
});
this.lineBar.update();
我试图将该时间转换为毫秒,但在屏幕上看起来很丑陋,用户需要将其转换回小时、分钟、秒和毫秒,这对客户来说太糟糕了:(
【问题讨论】:
标签: javascript angular ionic-framework charts chart.js