ChartJS 设置ng 2-图表圆环的剪切值

mspsb9vt  于 2023-03-29  发布在  Chart.js
关注(0)|答案(1)|浏览(164)

here相同的问题,但我得到以下错误:Type 'keyof ChartTypeRegistry' is not assignable to type '"doughnut"'.当我尝试实现它。
查看图表配置文档并发现

interface ChartTypeRegistry {
 ...
  pie: {
    chartOptions: PieControllerChartOptions;
    datasetOptions: PieControllerDatasetOptions;
    defaultDataPoint: PieDataPoint;
    metaExtensions: PieMetaExtensions;
    parsedDataType: number;
    scales: keyof CartesianScaleTypeRegistry;
  };
  doughnut: {
    chartOptions: DoughnutControllerChartOptions;
    datasetOptions: DoughnutControllerDatasetOptions;
    defaultDataPoint: DoughnutDataPoint;
    metaExtensions: DoughnutMetaExtensions;
    parsedDataType: number;
    scales: keyof CartesianScaleTypeRegistry;
  };

图中有一个切口,但是

public doughnutChartOptions: ChartConfiguration['options'] = {
    doughnut: {
      datasets: {
       /can't access cutout here /
      }
    }
...
};

但不知道如何访问chartOptions。我使用的是最新版本的ng 2-charts和chart.js chart.js@4.0.1 ng 2-charts@4.1.1任何帮助都将不胜感激!

qeeaahzv

qeeaahzv1#

将图表类型添加到选项以正确Map:

public doughnutChartOptions: ChartConfiguration<'doughnut'>['options'] = {
    cutout: '50%', // percentage of chart to cut out of the middle
    //cutout: 100, // pixels
...
};

相关问题