代码之家  ›  专栏  ›  技术社区  ›  LiefLayer

使用多行动态向折线图js添加数据

  •  0
  • LiefLayer  · 技术社区  · 7 年前

    我需要在角5的线图上显示一组n条线。

    我在组件上创建了这样的折线图:

    lineRecoveriesChartData: any[] = [    {data: this.arrayOfResult, label: '', borderColor: "black", fill: false}  ];
    

    在我从服务器post接收到数据后,我尝试用如下方式加载它们:

    for(var i = 0; i < 10; i++){
            this.lineResult = arrayOfIntegerReceivedFromServer[i];
            this.lineRecoveriesChartData.push(
                this.lineResult
            );
        }
    

    当然这不是我唯一尝试过的。。。我尝试使用数据集,我尝试设置超时,我尝试使用图表的更新功能。。。 但它总是无法更新我在图表上的数据。

    我知道这样更静态的东西:

    lineRecoveriesChartData: any[] = [    {data: this.arrayFromServer, label: '', borderColor: "black", fill: false},  {data: this.array2FromServer, label: '', borderColor: "black", fill: false} ];
    

    可以,但我需要生成多行,我不知道有多少行。

    1 回复  |  直到 7 年前
        1
  •  0
  •   LiefLayer    7 年前

    秘诀是不要在初始数组中放入任何数据,在数据数组中有数据之前使用ngif。

    推荐文章