如何在ng2-charts中动态地将数据绑定到baseChart

时间:2018-06-19 07:15:16

标签: html angular ng2-charts

我无法将数据绑定到我的图表。如何使它出现。因为当我输入数字时,会出现图表。但是当我们使用变量来存储数字时,如何使图形工作。

代码 -

component.ts

    showData(){

    //code 

   this.entireSuccessResult = this.result1.length;

   this.entireErrorResult = this.result2.length;

       }


   public barChartOptionsEntire: any = {
    scaleShowVerticalLines: false,
    responsive: true
      };
     public barChartLabelsEntire: string[] = ['Success', 'Error', 
    'abcd','efgh'];
     public barChartTypeEntire = 'bar';
     public barChartLegendEntire = true;

     public barChartDataEntire: any[] = [
     { data: [this.entireSuccessResult,10,20,30], label: 'Success' },
      { data: [this.entireErrorResult,10,20], label: 'Error' }
       ];

component.html

    <div class="card-body" >
          <div class="chart-wrapper">

            <canvas baseChart class="chart"   
      [datasets]="barChartDataEntire"
               [labels]="barChartLabelsEntire"   
     [options]="barChartOptionsEntire"      
     [legend]="barChartLegendEntire"
              [chartType]="barChartTypeEntire"        
     (chartHover)="chartHovered($event)" 
     (chartClick)="chartClicked($event)"></canvas>

          </div>
        </div>

0 个答案:

没有答案