首页 > 解决方案 > ChartJs - 饼图 - 如何删除饼图上的标签

问题描述

chart.js在我的应用程序中使用饼图进行可视化。我正在使用一个插件chartjs-plugin-piechart-outlabels来将标签显示为饼图中的外段。

一切正常,除了标签存在于饼图上,这是我不想要的,因为我将标签显示为外段。

我查看了文档并找不到解决方案,还查看了一些示例。

public static readonly pieChartOptions: ChartOptions = {
responsive: true,
maintainAspectRatio: false,
legend: {
  display: false
},
tooltips: {
  enabled: true
},
layout: {
  padding: {
    left: 0,
    right: 0,
    top: 70,
    bottom: 0
  }
},
plugins: {
  outlabels: {
    display: true,
    borderWidth: 2,
    lineWidth: 2,
    padding: 3,
    textAlign: 'center',
    stretch: 15,
    font: {
      resizable: true,
      minSize: 12,
      maxSize: 18
    },
    valuePrecision: 1,
    percentPrecision: 2
  }
}

};

实际结果

标签: angularchart.jschartjs-2.6.0

解决方案


您需要关闭示例标签,如下所示:

options: {
  plugins: {
    datalabels: {
      display: false
    }
    outlabels: {
      display: true
    }
  }
}

推荐阅读