chartjs-plugin-annotations not displayed in angular 5

前端 未结 4 1503
名媛妹妹
名媛妹妹 2021-01-06 00:10

While using the chart.js and the plugin chartjs-plugin-annotation, annotations are not showing while using angular 5, no error messages are displayed.

I have created

4条回答
  •  耶瑟儿~
    2021-01-06 01:03

    As an adition of what Ade said. You can also add the plugin this way

    import { ChartOptions } from 'chart.js';
    import * as ChartAnnotation from 'chartjs-plugin-annotation';
    
    this.chart = new Chart('canvas', {
      ...
      options: {
        ...
        annotation: { ... }
      } as ChartOptions,
      plugins: [ChartAnnotation]
    });
    

    Adding the {...} as ChartOptions makes that TypeScript doesn't complain

提交回复
热议问题