Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.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
Javascript 当使用Angular从HTTP请求追溯推送数据点时,Chart.js数据会倒退_Javascript_Angular_Typescript_Http_Chart.js - Fatal编程技术网

Javascript 当使用Angular从HTTP请求追溯推送数据点时,Chart.js数据会倒退

Javascript 当使用Angular从HTTP请求追溯推送数据点时,Chart.js数据会倒退,javascript,angular,typescript,http,chart.js,Javascript,Angular,Typescript,Http,Chart.js,我试图从http请求中推送这些体重数据集,GET请求返回以下数据 bodyweight: 2020: 11: 06: {logId: 5, value: 70} 12: 17: {logId: 2, value: 82} ... 2021: 01: 02: {logId: 9, value: 81.6} 04: {

我试图从http请求中推送这些体重数据集,GET请求返回以下数据

bodyweight:
    2020:
        11:
            06: {logId: 5, value: 70}
        12:
            17: {logId: 2, value: 82}
            ...
    2021:
        01:
            02: {logId: 9, value: 81.6}
            04: {logId: 13, value: 75.4}
            10: {logId: 10, value: 80}
            13: {logId: 11, value: 87}
            14: {logId: 12, value: 90}
            17: {logId: 14, value: 95}
            25: {logId: 15, value: 82}
根据这些数据,回顾性地添加了数据点2021:01:02和2021:01:04,即,添加的时间晚于2021年1月2日/4日

将这些数据添加到图表中的方法如下:

this.metricsHttpService.getTrackingMetrics(clientId).subscribe((res) => {
      if (res.metric.bodyweight) {
        for (const year in res.metric.bodyweight) {
          if (res.metric.bodyweight[year]) {
            for (const month in res.metric.bodyweight[year]) {
              if (res.metric.bodyweight[year][month]) {
                for (const date in res.metric.bodyweight[year][month]) {
                  if (res.metric.bodyweight[year][month][date]) {
                    this.onUpdateChart(year, month, date, res.metric.bodyweight[year][month][date].value);
                  }
                }
              }
            }
          }
        }
      }
如您所见,2021年1月2日和4日的数据点是向后循环的,而不是按时间顺序显示的线。有什么想法吗?非常感谢你;我对chart.js还是新手


Chartjs将根据项目的索引绘制线,因此,如果您最后添加的项目位于数组的末尾,这是正确的行为,要获得所需的行为,您必须将值插入数组中的正确位置