Commit 806c8897 by 前端

饼状图添加label

1 parent 836b2ecc
<template> <template>
<div> <div>
<p class="line-color-title">{{title}}</p> <p class="line-color-title">{{title}}</p>
<div v-if="data" ref="pieChart" style="margin-top:10px;width: 100%; height:25vh;"></div> <div v-if="data" ref="pieChart" style="margin-top:10px;width: 100%; height:24.5vh;"></div>
</div> </div>
</template> </template>
...@@ -47,10 +47,19 @@ export default { ...@@ -47,10 +47,19 @@ export default {
}); });
}, },
createFormatter(params) { createFormatter(params) {
const styleKey = 'style' + (params.dataIndex % this.colors.length); const dataIndex = params.dataIndex;
return `{${styleKey}|${params.value}%}\n\n{b|${params.name}${params.displayQuantity?(params.displayQuantity+ '人'): '' }}`; const dataItem = this.data[dataIndex]; // 获取当前索引下的数据项
const styleKey = 'style' + (dataIndex % this.colors.length);
// 确保dataItem存在,并且displayQuantity已定义
const displayQuantityText = dataItem && dataItem.displayQuantity !== undefined && dataItem.displayQuantity !== null
? '('+dataItem.displayQuantity + '人' + ')'
: '';
return `{${styleKey}|${params.value}%}\n\n{b|${params.name}${displayQuantityText}}`;
}, },
drawChart() { drawChart() {
this.generateRichStyles(); // 生成动态样式 this.generateRichStyles(); // 生成动态样式
const chart = echarts.init(this.$refs.pieChart); const chart = echarts.init(this.$refs.pieChart);
...@@ -98,7 +107,7 @@ export default { ...@@ -98,7 +107,7 @@ export default {
@media screen and (min-resolution: 2dppx) { @media screen and (min-resolution: 2dppx) {
/* 针对高分辨率显示屏的样式调整 */ /* 针对高分辨率显示屏的样式调整 */
.pieChart { .pieChart {
height: 30vh; /* 可能需要更大的高度 */ height: 28vh; /* 可能需要更大的高度 */
} }
} }
</style> </style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!