parent
98ec61a753
commit
1daf3eace4
@ -0,0 +1,93 @@
|
||||
<template>
|
||||
<div class="container">
|
||||
<div id="pieChart" style="width: 700px; height: 200px;"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import * as echarts from 'echarts';
|
||||
import { getAllProjects } from '@/api/ManageApi/index';
|
||||
export default {
|
||||
name: 'ChubeiXm',
|
||||
mounted() {
|
||||
this.initPieChart();
|
||||
},
|
||||
methods: {
|
||||
async initPieChart() {
|
||||
try {
|
||||
const res = await getAllProjects();
|
||||
if (res.code === 200) {
|
||||
const chartData = this.formatData(res.data);
|
||||
this.renderChart(chartData);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取数据失败:', error);
|
||||
}
|
||||
},
|
||||
formatData(rawData) {
|
||||
const mapping = {
|
||||
'1': '新供地实施',
|
||||
'2': '存量产业用地改扩建'
|
||||
};
|
||||
|
||||
return rawData.map(item => ({
|
||||
name: mapping[item.ssgnq] || '未知类型',
|
||||
value: item.count
|
||||
}));
|
||||
},
|
||||
renderChart(data) {
|
||||
const chartDom = document.getElementById('pieChart');
|
||||
const myChart = echarts.init(chartDom);
|
||||
|
||||
const option = {
|
||||
tooltip: {
|
||||
trigger: 'item',
|
||||
formatter: '{b}: {d}%'
|
||||
},
|
||||
legend: {
|
||||
orient: 'horizontal',
|
||||
bottom: '0%',
|
||||
itemGap: 30
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: '储备项目统计',
|
||||
type: 'pie',
|
||||
radius: '50%',
|
||||
data: data,
|
||||
color: ['#409EFF', '#36CBCB'],
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
shadowBlur: 10,
|
||||
shadowOffsetX: 0,
|
||||
shadowColor: 'rgba(0, 0, 0, 0.5)'
|
||||
},
|
||||
label: {
|
||||
show: true,
|
||||
formatter: '{b}: {d}%'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
myChart.setOption(option);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding-bottom: 2%;
|
||||
}
|
||||
|
||||
/* #pieChart {
|
||||
margin: 20px auto;
|
||||
} */
|
||||
</style>
|
Loading…
Reference in new issue