【发布时间】:2024-01-10 04:06:01
【问题描述】:
我是一名学习vue的学生。 我使用 Vue-chartjs 绘制了一个图表,我想在饼图上显示该值。 但我不知道该怎么办。
请帮帮我...
目前情况(图片):enter image description here
我的愿望(图片):enter image description here
Vue.component('pie-chart', {
extends : VueChartJs.Pie,
props: ['data', 'options'],
mounted(){
this.renderPieChart();
},
computed: {
attendanceData : function(){
return this.data
}
},
methods : {
renderPieChart : function(){
this.renderChart(
{
labels: ['a','b','c','d'],
datasets: [{
backgroundColor: ['#10a236', '#f9cd41', '#fe7272', '#5c7add'],
data: [10,20,30,40]
}]
},
{
responsive: true,
maintainAspectRatio: false,
pieceLabel: {
render: 'value',
precision: 1,
}
}
)
}
},
watch : {
attendanceData : function(){
this.$data._chart.destroy();
this.renderPieChart();
}
}
});
【问题讨论】:
-
两张照片看起来一样...
-
你试过添加插件吗?例如 chartjs-plugin-datalabels 你可以在这里找到更多信息 chartjs-plugin-datalabels.netlify.com 和 vue-chartjs.org/#/home?keyword=label&id=inline-plugins
-
@AnyMoose 对不起!!!我换了图片!
-
我不敢相信这还不是 ChartJS 中的内置功能。
标签: laravel vue.js chart.js vue-chartjs