diff --git a/src/renderer/src/views/classTask/container/classOverview/distribution/echarts.vue b/src/renderer/src/views/classTask/container/classOverview/distribution/echarts.vue index d139c2f..4ba8db2 100644 --- a/src/renderer/src/views/classTask/container/classOverview/distribution/echarts.vue +++ b/src/renderer/src/views/classTask/container/classOverview/distribution/echarts.vue @@ -32,6 +32,8 @@ function getColor(index) { // 初始化图表 function initChart() { const myChart = echarts.init(chartRef.value); + const total = dataList.value.reduce((acc, cur) => acc + cur.value, 0); // 计算总数 + const options = { tooltip: { trigger: 'axis', @@ -70,7 +72,11 @@ function initChart() { label: { show: true, position: 'top', - formatter: '{c}人', + formatter: params => { + const value = dataList.value[params.dataIndex].value; + const percentage = ((value / total) * 100).toFixed(2); // 计算百分比并保留两位小数 + return `${percentage}%`; // 显示为百分比形式 + }, color: '#333', fontSize: 12 }