|
@@ -7,6 +7,35 @@ const props = defineProps({
|
|
|
})
|
|
|
let chart, option;
|
|
|
const pieChart3d = ref();
|
|
|
+const legendItems = ref([
|
|
|
+ {
|
|
|
+ name: '有管理单位(物业)',
|
|
|
+ color: '#5ef8c9'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '有管理单位(非物业)',
|
|
|
+ color: '#5e92f8'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '居民自主管理',
|
|
|
+ color: '#F4F85E'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '街道社区代管',
|
|
|
+ color: '#FC2626'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '其他管理形式',
|
|
|
+ color: '#1162fe'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '无管理主体',
|
|
|
+ color: '#FF7A00'
|
|
|
+ },
|
|
|
+])
|
|
|
+function showValue(name) {
|
|
|
+ return props.fierList.find(item => item.name === name)?.value
|
|
|
+}
|
|
|
function initChart() {
|
|
|
chart = echarts.init(pieChart3d.value);
|
|
|
// 传入数据生成 option
|
|
@@ -14,6 +43,12 @@ function initChart() {
|
|
|
...item,
|
|
|
label: {
|
|
|
show: true
|
|
|
+ },
|
|
|
+ itemStyle: {
|
|
|
+ color: (() => {
|
|
|
+ const temp = legendItems.value.find(i => i.name === item.name)
|
|
|
+ return temp.color
|
|
|
+ })()
|
|
|
}
|
|
|
})),
|
|
|
0.75
|
|
@@ -228,22 +263,6 @@ function getPie3D(pieData, internalDiameterRatio) {
|
|
|
typeof internalDiameterRatio !== "undefined"
|
|
|
? (1 - internalDiameterRatio) / (1 + internalDiameterRatio)
|
|
|
: 1 / 3;
|
|
|
-
|
|
|
- let labelSeries = {
|
|
|
- id: 'labelSeries',
|
|
|
- type: 'bar3D',
|
|
|
- //zlevel:-9,
|
|
|
- barSize: [0, 0],
|
|
|
- data: [],
|
|
|
- label: {
|
|
|
- show: true,
|
|
|
- formatter: function (params) {
|
|
|
- return `${params.value[3]}`;
|
|
|
- },
|
|
|
- color: '#fff',
|
|
|
- fontSize: '18px'
|
|
|
- },
|
|
|
-};
|
|
|
// 为每一个饼图数据,生成一个 series-surface 配置
|
|
|
for (let i = 0; i < pieData.length; i += 1) {
|
|
|
sumValue += pieData[i].value;
|
|
@@ -292,47 +311,9 @@ function getPie3D(pieData, internalDiameterRatio) {
|
|
|
);
|
|
|
startValue = endValue;
|
|
|
legendData.push(series[i].name);
|
|
|
- // 判断增加 label 效果 @20210613
|
|
|
- if (pieData[i].label && pieData[i].label.show) {
|
|
|
- let labelRadian = (series[i].pieData.startRatio + series[i].pieData.endRatio) * Math.PI;
|
|
|
- labelSeries.data.push({
|
|
|
- name: series[i].name,
|
|
|
- value: [Math.cos(labelRadian), Math.sin(labelRadian), 1.2, series[i].pieData.value],
|
|
|
- itemStyle: {
|
|
|
- opacity: 1,
|
|
|
- },
|
|
|
- });
|
|
|
- }
|
|
|
}
|
|
|
- // 将 labelSeries 添加进去 @20210613
|
|
|
- series.push(labelSeries);
|
|
|
// 准备待返回的配置项,把准备好的 legendData、series 传入。
|
|
|
const option = {
|
|
|
- color: [ "#FC2626", "#1162fe", "#F4F85E", "#FF7A00", "#5ef8c9", "#5e92f8"],
|
|
|
- legend: {
|
|
|
- // type: "scroll",
|
|
|
- data: ["有管理单位(物业)", "有管理单位(非物业)", "居民自主管理", "街道社区代管", "其他管理形式", "无管理主体"],
|
|
|
- icon: "roundRect",
|
|
|
- orient: "vertical",
|
|
|
- padding: 5,
|
|
|
- itemGap: 10,
|
|
|
- top: "8%",
|
|
|
- right: 0,
|
|
|
- itemWidth: 10, // 设置宽度
|
|
|
- itemHeight: 10, // 设置高度
|
|
|
- selectedMode: true,
|
|
|
- textStyle: {
|
|
|
- color: "#FFFFFF",
|
|
|
- fontSize: 14,
|
|
|
- lineHeight: 14,
|
|
|
- rich: {
|
|
|
- a: {
|
|
|
- // verticalAlign: "middle",
|
|
|
- },
|
|
|
- },
|
|
|
- padding: [0, 0, -3, 0],
|
|
|
- },
|
|
|
- },
|
|
|
tooltip: {
|
|
|
formatter: (params) => {
|
|
|
if (params.seriesName !== "mouseoutSeries") {
|
|
@@ -413,6 +394,11 @@ function getPie3D(pieData, internalDiameterRatio) {
|
|
|
<template>
|
|
|
<div class="container">
|
|
|
<div ref="pieChart3d" class="chart"></div>
|
|
|
+ <ul class="legend">
|
|
|
+ <li v-for="(legend,idx) in legendItems" @click="$emit('click-item', legend.name)" :style="{
|
|
|
+ '--bg': legend.color
|
|
|
+ }" :key="idx">{{ legend.name }}({{ showValue(legend.name) }})</li>
|
|
|
+ </ul>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
@@ -423,6 +409,29 @@ function getPie3D(pieData, internalDiameterRatio) {
|
|
|
position: relative;
|
|
|
}
|
|
|
|
|
|
+.container .legend {
|
|
|
+ position: absolute;
|
|
|
+ right: 10px;
|
|
|
+ top: 24px;
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ gap: 10px;
|
|
|
+ z-index: 500;
|
|
|
+ & > li {
|
|
|
+ list-style: none;
|
|
|
+ cursor: pointer;
|
|
|
+ font-size: 12px;
|
|
|
+ }
|
|
|
+ & > li::before {
|
|
|
+ content: "";
|
|
|
+ display: inline-block;
|
|
|
+ margin-right: 5px;
|
|
|
+ width: 10px;
|
|
|
+ height: 10px;
|
|
|
+ border-radius: 2px;
|
|
|
+ background-color: var(--bg);
|
|
|
+ }
|
|
|
+}
|
|
|
.container::after {
|
|
|
content: "";
|
|
|
position: absolute;
|