<template>
<div style="width: 100%;height:100%;text-align: center;">
<div :id="pieShowId" class="pie" style="width: 100%;height: 100%"></div>
</div>
</template>
<script>
//import NProgress from 'nprogress'
export default {
props: ["optionData", "pieShowId", "titleText"], //传递的参数数组,id区分,名字区分
data() {
return {
myChart: {}
};
},
mounted() {
this.initdata();
window.addEventListener("resize", () => {
this.myChart.resize(); //动态计算大小
});
},
methods: {
initdata() {
this.myChart = this.$echarts.init(
document.getElementById(this.pieShowId)
);
this.myChart.setOption({
color: ["#0FCCD7", "#F57140", "#FBB307", "#B665B7", "#5488F1"],
title: {
text: this.titleText ? this.titleText : "",
left: "center"
},
tooltip: {
trigger: "item",
formatter: function (params, ticket, callback) { //处理数据函数
if(params.data.custom){
return `${params.data.name}:${params.data.customValue}`
}else{
return `${params.data.name}:${params.data.value}`
}
}
},
series: [
{
name: "",
type: "pie",
center: ["50%", "50%"],
radius: ["30%", "80%"],
label: {
normal: {
position: "inner"
}
},
data: this.optionData,
itemStyle: {
normal: {
borderWidth: 0,
borderColor: "#fff"
},
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0
// shadowColor: "rgba(0, 0, 0, 0.8)"
}
}
}
]
});
}
}
};
</script>
<style scoped>
</style>
echarts饼状图共用组件
最新推荐文章于 2023-05-25 11:23:45 发布