首页 > 解决方案 > 在初始化之前使用属性“octomber”有问题

问题描述

  @Component({
      selector: 'app-adminpanel',
      templateUrl: './adminpanel.component.html',
      styleUrls: ['./adminpanel.component.scss']
    })
    export class AdminpanelComponent implements OnInit {
      msg='';
      november;
     
  constructor(private _service : RegistrationService) {  
       this.getStatOctDetails();        
  }
    
       public barChartOptions: ChartOptions = {
        responsive: true,
        // We use these empty structures as placeholders for dynamic theming.
        scales: { xAxes: [{}], yAxes: [{}],
        plugins: {
          datalabels: {
            anchor: 'end',
            align: 'end',
          }
        }
      };
      public barChartLabels: Label[] = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
      public barChartType: ChartType = 'bar';
      public barChartLegend = true;
      public barChartPlugins = [pluginDataLabels];
    
      public barChartData: ChartDataSets[] = [
        { data: [this.octomber, 7, 2, 9, 5, 3, 1], label: 'Series A' },
        { data: [28, 48, 40, 19, 86, 27, 90], label: 'Series B' }
      ];

在上面几行出现初始化问题之前使用了属性“octomber”

      ngOnInit(): void {
       
      }

      getStatOctDetails(){
        this._service.adminStatMonthOct().subscribe(
          data => {console.log(data)
          // this._router.navigate(['/login'])
          this.octomber = data;
    
        },
          error =>{ 
            console.log("error occur") 
            this.msg=error.error;
            ;
          }
        )
      } 
```

我使用了 Spring Boot 框架和 Angular。我从弹簧靴中获取 10 月的值(变量)。但是我在 10 月添加了 null (octomber=null;),然后错误消失了,但没有为我的图表显示任何值。我的项目的 octomber 值应该是 2

标签: angularchart.js

解决方案


推荐阅读