chart.js升级和与angular版本的兼容性

rbpvctlc  于 2023-04-11  发布在  Chart.js
关注(0)|答案(1)|浏览(180)

我在我的项目中使用angular 9,我有chart.js 2.9.4版本,我想将chartjs版本升级到最新版本我尝试安装chartjs最新版本,但似乎不起作用我下面的图表只在chartjs 2.9.4上工作......我的问题是我可以升级到最新的chartjs吗?在哪里我可以看到与angular.js的兼容版本列表

bar-chart.component.html

<div class="chart-container">
      <canvas  id="MyChart" >{{ chart }}</canvas>
</div>

bar-chart.component.ts

import { Component, OnInit } from '@angular/core';
import { Chart } from 'chart.js';
@Component({
  selector: 'app-bar-chart',
  templateUrl: './bar-chart.component.html',
  styleUrls: ['./bar-chart.component.scss']
})
export class BarChartComponent implements OnInit {

  constructor() { }
  public chart: any;

  ngOnInit(): void {
    this.createChart();
  }

  createChart(){
  
    this.chart = new Chart("MyChart", {
      type: 'bar', //this denotes tha type of chart

      data: {// values on X-Axis
        labels: ['2022-05-10', '2022-05-11', '2022-05-12','2022-05-13',
                                 '2022-05-14', '2022-05-15', '2022-05-16','2022-05-17', ], 
           datasets: [
          {
            label: "Sales",
            data: ['467','576', '572', '79', '92',
                                 '574', '573', '576'],
            backgroundColor: 'blue'
          },
          {
            label: "Profit",
            data: ['542', '542', '536', '327', '17',
                                     '0.00', '538', '541'],
            backgroundColor: 'limegreen'
          }  
        ]
      },
      options: {
        aspectRatio:2.5
      }
      
    });
  }

}

我想知道charjs版本与angular版本的兼容性

lf3rwulv

lf3rwulv1#

@ganesh-giri我相信你可以在angular 9中使用最新的Chart.js。由于Chart.js是一个不同的库,它与Angular无关,它是一个通用的Js/Ts库。然而,如果你在使用更新版本的Chart.js时遇到任何错误,请使用下面的链接。

相关问题