【发布时间】:2020-05-22 15:23:37
【问题描述】:
我正在使用VueChart js/ chart js 在我的 vue 项目中创建一个饼图,我想显示每个弧内的数据百分比,我们该怎么做?
我在 Vue 中的代码:
fillData() {
this.datacollection = {
labels: ['T', 'W', 'R', 'B'],
datasets: [
{
backgroundColor: [
'rgb(51,122,183)',
'rgb(226,142,65)',
'rgb(0,169,157)',
'rgb(217,83,79)',
],
data: [
this.tw.length,
this.w.length,
this.r.length,
this.b.length,
],
hoverBackgroundColor: ['#0275d8', '#f0ad4e', '#5cb85c', '#d9534f'],
},
],
};
this.options = {
responsive: true,
maintainAspectRatio: false,
devicePixelRatio: 2,
tooltips: {
enabled: true,
},
title: {
display: true,
text: 'Arcs state %',
position: 'bottom',
fontSize: 20,
},
};
},
更新 我尝试了@zb22 推荐的插件,但它不起作用。我确实通过 npm 安装了插件
this.options = {
plugins: {
labels: {
render: 'percentage',
fontColor: ['white', 'white', 'white'],
precision: 2,
},
},
};
我有类似下面的东西,只有当我将鼠标悬停在每个弧上时它才会显示数据
我的目标是显示我的图表如下:
【问题讨论】:
标签: javascript chart.js vue-chartjs