parent
17e9399b4a
commit
b4dfcc73d4
3 changed files with 518 additions and 110 deletions
Binary file not shown.
@ -0,0 +1,243 @@ |
|||||||
|
<template> |
||||||
|
<div class="pie_chart"> |
||||||
|
<div class="pie_box" id="pieChart"></div> |
||||||
|
<div class="pie_data"> |
||||||
|
<div class="data_txt" v-for="(item,index) in chartData" :key="item.name"> |
||||||
|
<div class="pie_color" :style="{background:startColor[index]}"></div> |
||||||
|
<div class="pie_txt">{{item.name}}</div> |
||||||
|
<div class="pie_txt">{{item.value}}</div> |
||||||
|
<div class="pie_txt">{{item.percent}}%</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</template> |
||||||
|
|
||||||
|
<script> |
||||||
|
export default { |
||||||
|
props:{ |
||||||
|
chartData:Array |
||||||
|
}, |
||||||
|
data() { |
||||||
|
return { |
||||||
|
pieChart:null, |
||||||
|
// lineData:[], |
||||||
|
// yData1:[], |
||||||
|
// yData2:[] |
||||||
|
// chartData:[], |
||||||
|
|
||||||
|
RealData: [], |
||||||
|
borderData: [], |
||||||
|
startColor: [ |
||||||
|
"#0e94eb", |
||||||
|
"#c440ef", |
||||||
|
"#efb013", |
||||||
|
"#2fda07", |
||||||
|
"#d8ef13", |
||||||
|
"#2e4af8", |
||||||
|
"#0eebc4", |
||||||
|
"#f129b1", |
||||||
|
"#17defc", |
||||||
|
"#f86363", |
||||||
|
], |
||||||
|
borderStartColor: [ |
||||||
|
"#0077c5", |
||||||
|
"#a819d7", |
||||||
|
"#c99002", |
||||||
|
"#24bc00", |
||||||
|
"#b6cb04", |
||||||
|
"#112ee2", |
||||||
|
"#00bd9c", |
||||||
|
"#ce078f", |
||||||
|
"#00b2cd", |
||||||
|
"#ec3c3c", |
||||||
|
], |
||||||
|
}; |
||||||
|
}, |
||||||
|
created() { |
||||||
|
// console.log(this.chartData) |
||||||
|
this.$nextTick(() => { |
||||||
|
console.log(this.chartData) |
||||||
|
|
||||||
|
this.createCharts(); |
||||||
|
}); |
||||||
|
}, |
||||||
|
methods: { |
||||||
|
createCharts() { |
||||||
|
this.pieChart = this.$echarts.init(document.getElementById("pieChart")); |
||||||
|
window.addEventListener("resize", ()=> { |
||||||
|
this.pieChart.resize(); |
||||||
|
}); |
||||||
|
this.chartData.map((item, index) => { |
||||||
|
var newobj = this.deepCopy(item); |
||||||
|
var newobj1 = this.deepCopy(item); |
||||||
|
this.RealData.push(newobj); |
||||||
|
this.borderData.push(newobj1); |
||||||
|
}); |
||||||
|
this.RealData.map((item, index) => { |
||||||
|
item.itemStyle = { |
||||||
|
normal: { |
||||||
|
color: { |
||||||
|
type: "linear", |
||||||
|
x: 0, |
||||||
|
y: 0, |
||||||
|
x2: 0, |
||||||
|
y2: 1, |
||||||
|
colorStops: [ |
||||||
|
{ |
||||||
|
offset: 0, |
||||||
|
color: this.startColor[index], // 0% 处的颜色 |
||||||
|
}, |
||||||
|
{ |
||||||
|
offset: 1, |
||||||
|
color: this.startColor[index], // 100% 处的颜色 |
||||||
|
}, |
||||||
|
], |
||||||
|
globalCoord: false, // 缺省为 false |
||||||
|
}, |
||||||
|
}, |
||||||
|
}; |
||||||
|
}); |
||||||
|
this.borderData.map((item, index) => { |
||||||
|
item.itemStyle = { |
||||||
|
normal: { |
||||||
|
color: { |
||||||
|
type: "linear", |
||||||
|
x: 0, |
||||||
|
y: 0, |
||||||
|
x2: 0, |
||||||
|
y2: 1, |
||||||
|
colorStops: [ |
||||||
|
{ |
||||||
|
offset: 0, |
||||||
|
color: this.borderStartColor[index], // 0% 处的颜色 |
||||||
|
}, |
||||||
|
{ |
||||||
|
offset: 1, |
||||||
|
color: this.borderStartColor[index], // 100% 处的颜色 |
||||||
|
}, |
||||||
|
], |
||||||
|
globalCoord: false, // 缺省为 false |
||||||
|
}, |
||||||
|
}, |
||||||
|
}; |
||||||
|
}); |
||||||
|
var option = { |
||||||
|
tooltip: { |
||||||
|
trigger: "item", |
||||||
|
// position: ['30%', '50%'], |
||||||
|
confine: true, |
||||||
|
formatter: "{a} <br/>{b}: {c} ({d}%)", |
||||||
|
}, |
||||||
|
series: [ |
||||||
|
// 主要展示层的 |
||||||
|
{ |
||||||
|
radius: ["50%", "85%"], |
||||||
|
center: ["50%", "50%"], |
||||||
|
type: "pie", |
||||||
|
label: { |
||||||
|
normal: { |
||||||
|
show: false, |
||||||
|
}, |
||||||
|
emphasis: { |
||||||
|
show: false, |
||||||
|
}, |
||||||
|
}, |
||||||
|
labelLine: { |
||||||
|
normal: { |
||||||
|
show: false, |
||||||
|
}, |
||||||
|
emphasis: { |
||||||
|
show: false, |
||||||
|
}, |
||||||
|
}, |
||||||
|
name: "派件入库量占比内容", |
||||||
|
data: this.RealData, |
||||||
|
}, |
||||||
|
// 边框的设置 |
||||||
|
{ |
||||||
|
radius: ["45%", "50%"], |
||||||
|
center: ["50%", "50%"], |
||||||
|
type: "pie", |
||||||
|
label: { |
||||||
|
normal: { |
||||||
|
show: false, |
||||||
|
}, |
||||||
|
emphasis: { |
||||||
|
show: false, |
||||||
|
}, |
||||||
|
}, |
||||||
|
labelLine: { |
||||||
|
normal: { |
||||||
|
show: false, |
||||||
|
}, |
||||||
|
emphasis: { |
||||||
|
show: false, |
||||||
|
}, |
||||||
|
}, |
||||||
|
animation: false, |
||||||
|
tooltip: { |
||||||
|
show: false, |
||||||
|
}, |
||||||
|
data: this.borderData, |
||||||
|
}, |
||||||
|
], |
||||||
|
}; |
||||||
|
|
||||||
|
this.pieChart.setOption(option); |
||||||
|
// this.myChart1.setOption(option); |
||||||
|
}, |
||||||
|
deepCopy(obj) { |
||||||
|
if (typeof obj !== "object") { |
||||||
|
return obj; |
||||||
|
} |
||||||
|
var newobj = {}; |
||||||
|
for (var attr in obj) { |
||||||
|
newobj[attr] = obj[attr]; |
||||||
|
} |
||||||
|
return newobj; |
||||||
|
}, |
||||||
|
}, |
||||||
|
}; |
||||||
|
</script> |
||||||
|
|
||||||
|
<style lang="scss" scoped> |
||||||
|
.pie_chart { |
||||||
|
width: 100%; |
||||||
|
height: 100%; |
||||||
|
display: flex; |
||||||
|
justify-content: space-between; |
||||||
|
align-items: center; |
||||||
|
|
||||||
|
.pie_box { |
||||||
|
width: 60%; |
||||||
|
height: 100%; |
||||||
|
// background: red; |
||||||
|
} |
||||||
|
|
||||||
|
.pie_data{ |
||||||
|
width: 39%; |
||||||
|
height: 100%; |
||||||
|
display: flex; |
||||||
|
flex-direction: column; |
||||||
|
justify-content: space-around; |
||||||
|
align-items: center; |
||||||
|
|
||||||
|
.data_txt{ |
||||||
|
width: 100%; |
||||||
|
display: flex; |
||||||
|
justify-content: space-between; |
||||||
|
align-items: center; |
||||||
|
|
||||||
|
.pie_color{ |
||||||
|
width: 0.24rem; |
||||||
|
height: 0.2rem; |
||||||
|
border-radius: 30%; |
||||||
|
} |
||||||
|
} |
||||||
|
.pie_txt{ |
||||||
|
color:#fff; |
||||||
|
font-size: 0.18rem; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
</style> |
||||||
Loading…
Reference in new issue