You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
3.6 KiB

2 months ago
<template>
1 month ago
<!-- 投资主体 -->
<div style="width: 100%; height: 100%;">
2 weeks ago
<div class="itemsall">
<span>{{ functionnumber }}</span>
<span>项目总数</span>
</div>
<div ref="chart" style="width: 30rem; height: 100%;"></div>
</div>
1 month ago
</template>
<script>
import * as echarts from 'echarts';
import { investall } from '@/api/ManageApi/index';
export default {
name: 'RingChart',
props: {
years: {
type: String,
default: new Date().getFullYear().toString()
}
},
1 month ago
data() {
return {
functionnumber: 0,
1 month ago
chartData: [
{ value: 54, name: '国企', itemStyle: { color: '#36C3FB' } },
{ value: 65, name: '民企', itemStyle: { color: '#5B76F9' } },
{ value: 32, name: '外企', itemStyle: { color: '#FAC858' } },
3 weeks ago
{ value: 32, name: '其他', itemStyle: { color: '#50DFB3' } },
1 month ago
],
};
},
mounted() {
this.getData();
console.log("invest.vue: mounted with years:", this.years); // 调试日志
},
watch: {
years: {
immediate: true,
handler(newVal) {
console.log("invest.vue: years changed to:", newVal); // 调试日志
this.getData();
}
}
1 month ago
},
methods: {
async getData() {
console.log("invest.vue: getData called with years:", this.years); // 调试日志
const response = await investall({
years: this.years,
});
1 month ago
if (response && response.code === 200 && response.data) {
2 weeks ago
const totalCount = response.data.reduce((sum, item) => sum + item.count, 0);
this.functionnumber = totalCount;
1 month ago
this.chartData = this.processData(response.data);
this.renderChart();
} else {
console.error("invest.vue: 获取数据失败:", response); // 调试日志
}
2 months ago
},
1 month ago
processData(data) {
2 weeks ago
const names = ['国企', '民企', '外企', '其他'];
1 month ago
const counts = data.map(item => item.count);
return names.map((name, index) => ({
value: counts[index] || 0,
name: name,
itemStyle: { color: ['#36C3FB', '#5B76F9', '#FAC858', '#50DFB3'][index] },
1 month ago
}));
},
renderChart() {
const chartDom = this.$refs.chart;
const myChart = echarts.init(chartDom);
const option = {
tooltip: {
trigger: 'item'
},
legend: {
orient: 'vertical',
right: '18.5%',
top: 'center',
itemGap: 18,
1 month ago
formatter: function (name) {
const item = this.chartData.find(item => item.name === name);
return `${name} ${item.value}`;
}.bind(this)
},
series: [
{
name: '项目分布',
type: 'pie',
radius: ['40%', '60%'],
center: ['30%', '50%'],
data: this.chartData,
label: {
show: false
1 month ago
},
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
2 months ago
}
}
1 month ago
}
]
};
myChart.setOption(option);
2 months ago
}
1 month ago
}
};
</script>
2 weeks ago
<style scoped>
.itemsall {
position: absolute;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
top: 35%;
left: 23%;
}
.itemsall span:nth-child(1) {
font-family: DINbold;
font-weight: 500;
font-size: 1.25rem;
color: #292C33;
text-align: left;
font-style: normal;
text-transform: none;
}
.itemsall span:nth-child(2) {
font-family: alibold;
font-weight: 400;
font-size: 0.68rem;
color: #9E9E9E;
text-align: left;
font-style: normal;
text-transform: none;
}
</style>