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.

76 lines
2.3 KiB

2 months ago
<template>
2 months ago
<div ref="chart" style="width: 30rem; height: 15rem;"></div>
2 months ago
</template>
<script>
import * as echarts from 'echarts';
export default {
2 months ago
name: 'RingChart',
2 months ago
mounted() {
2 months ago
this.renderChart();
2 months ago
},
methods: {
2 months ago
renderChart() {
const chartDom = this.$refs.chart;
const myChart = echarts.init(chartDom);
2 months ago
2 months ago
const option = {
2 months ago
tooltip: {
2 months ago
trigger: 'item'
},
legend: {
orient: 'vertical', // 图例垂直排列
right: '10%', // 图例在右侧
top: 'center', // 图例垂直居中
itemGap: 20, //右侧间隔
formatter: function (name) {
// 自定义图例显示格式
const data = [
{ value: 54, name: '高贸区' , itemStyle:{color:'#36C3FB'}},
{ value: 65, name: '科创区' , itemStyle:{color:'#5B76F9'} },
{ value: 32, name: '度假区' , itemStyle:{color:'#F08445'} },
{ value: 25, name: '商务区' , itemStyle:{color:'#F6B600'} },
{ value: 15, name: '苏相合作区' , itemStyle:{color:'#50DFB3'} }
];
// 文本标签
const item = data.find(item => item.name === name);
return `${name} ${item.value}${((item.value / 384) * 100).toFixed(1)}%`;
}
2 months ago
},
series: [
{
name: '项目分布',
type: 'pie',
2 months ago
radius: ['40%', '60%'],
2 months ago
center: ['30%', '50%'],
data: [
{ value: 54, name: '高贸区' , itemStyle:{color:'#36C3FB'}},
{ value: 65, name: '科创区' , itemStyle:{color:'#5B76F9'} },
{ value: 32, name: '度假区' , itemStyle:{color:'#F08445'} },
{ value: 25, name: '商务区' , itemStyle:{color:'#F6B600'} },
{ value: 15, name: '苏相合作区' , itemStyle:{color:'#50DFB3'} }
],
2 months ago
label: {
2 months ago
show: false // 隐藏饼图内部的标签
2 months ago
},
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
2 months ago
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
2 months ago
};
2 months ago
myChart.setOption(option);
}
}
2 months ago
};
</script>
<style scoped>
2 months ago
/* 你可以在这里添加样式 */
2 months ago
</style>