环路数据并绘制图表,NGX-线图,(loop data and draw chart , ngx-l

2019-10-30 03:33发布

我在角度和打字稿一个新手。

我一直在使用服务JSON数据,在这里:

"data": 
[
    {   
        "invoice": [
            {
              "date": "2017-02-23",
              "nbre": 1
            },
            {
              "date": "2017-02-25",
              "nbre": 0
            },
            {
              "date": "2017-02-26",
              "nbre": 5
            }
            ...
        ]

        "order": [
            {
              "date": "2017-02-01",
              "nbre": 0
            },
            {
              "date": "2017-02-12",
              "nbre": 7
            },
            {
              "date": "2017-02-23",
              "nbre": 10
            }
            ...
        ]

    }
]

发票和订单数是144。

这里是我的代码:dashbord.component.html

<ngx-charts-line-chart
                [view]="view"
                [scheme]="colorScheme"
                [results]="multi"
                [gradient]="gradient"
                [xAxis]="showXAxis"
                [yAxis]="showYAxis"
                [legend]="showLegend"
                [showXAxisLabel]="showXAxisLabel"
                [showYAxisLabel]="showYAxisLabel"
                [xAxisLabel]="xAxisLabel"
                [yAxisLabel]="yAxisLabel"
                [autoScale]="autoScale"
                [timeline]="timeline"
                (select)="onSelect($event)">
      </ngx-charts-line-chart>

dashbord.component.ts

  dataChart: any[];
  this.loadChartNouvo();
  private loadChartNouvo(){
    this._myRestService.getChartData().subscribe(
     res=>{  console.log(res['data']);
       if (res['status_code'] === 200){
          for (let i in res['data']['invoice']) {
           this.dataChart[0].series.push({"name":res['data']['invoice']['date'][i], "value":res['data']['invoice']['nbre'][i]});
        }

       }
     },err=>{}
        )
          }

如何做一个循环我JSON数据,以显示与NGX图?

并使用循环如何把系列名称(图表名称)?

注:请原谅我的英语,

先感谢您

文章来源: loop data and draw chart , ngx-line-chart,