This commit is contained in:
chengdandan 2023-03-23 08:44:17 +08:00
parent 960cb31a67
commit 28eeaa0e29
1 changed files with 336 additions and 139 deletions

View File

@ -9,7 +9,8 @@
<div class="jsBox"> <div class="jsBox">
<div class="bogJs" v-for="(item, i) in pieData" :key="i"> <div class="bogJs" v-for="(item, i) in pieData" :key="i">
<div class="jsChild"> <div class="jsChild">
<span style="background: #00B3FF;"></span> <span :style="item.color"></span>
<!-- <span :background="item.color"></span> -->
<span>{{item.groupName}}</span> <span>{{item.groupName}}</span>
</div> </div>
<div class="js2Child"> <div class="js2Child">
@ -54,13 +55,13 @@ export default {
data() { data() {
return { return {
totalPer:'', totalPer:0,
// pieData:[], pieDataNew:[],
color:['#00B3FF','#F1E453','#F85B60','#00A572', '#008AA4', '#7968D9', '#C7A73E'], color:['background-color:#00B3FF','background-color:#F1E453','background-color:#F85B60','background-color:#00A572', 'background-color:#008AA4', 'background-color:#7968D9', 'background-color:#C7A73E'],
}; };
}, },
mounted() { mounted() {
// this.initCharts(); this.initCharts();
}, },
watch: { watch: {
// Echarts // Echarts
@ -74,7 +75,7 @@ export default {
deep: true, deep: true,
handler(newVal) { handler(newVal) {
console.log(newVal,'=============='); console.log(newVal,'==============');
this.initCharts(newVal) // this.initCharts(newVal)
this.changeNewVal(newVal) this.changeNewVal(newVal)
} }
@ -85,144 +86,340 @@ export default {
// //
changeNewVal(newVal){ changeNewVal(newVal){
console.log("newVal",newVal) console.log("newVal",newVal)
// var pieDataN = this.pieData.map((item,index) => { this.pieDataNew = newVal
// var pieDataN = []
// }) newVal.map((item,index) => {
var pieDataN = [] this.totalPer+=item.number
this.color.forEach((items,indexs) => { console.log("this.totalPer",this.totalPer)
pieDataN = this.pieData.map((item,index) => { this.color.forEach((items,indexs) => {
if(index==indexs){ if(index==indexs){
return item.color = items return item.color = items
} }
})
}) })
})
console.log("this.pieDataN",pieDataN)
}, },
initCharts(value) {
console.log(value,'============'); initCharts() {
let myChart = this.$echarts.init(this.$refs.chart); let myChart = this.$echarts.init(this.$refs.chart);
var placeHolderStyle = { // var placeHolderStyle = {
normal: { // normal: {
label: { // label: {
show: false, // show: false,
position: "center" // position: "center"
}, // },
labelLine: { // labelLine: {
show: false // show: false
}, // },
color: "#104841a3", // color: "#104841a3",
borderWidth: 0 // borderWidth: 0
}, // },
emphasis: { // emphasis: {
color: "#104841a3", // color: "#104841a3",
borderColor: "#00b3ff", // borderColor: "#00b3ff",
borderWidth: 0 // borderWidth: 0
} // }
}; // };
// // //
myChart.setOption({ // myChart.setOption({
series: [ // series: [
{ // {
name: '值', // name: '',
type: 'pie', // type: 'pie',
clockWise: true, // clockWise: true,
hoverAnimation: false, // hoverAnimation: false,
radius: ['92%', '97%'], // radius: ['92%', '97%'],
center: ['50%', '50%'], // center: ['50%', '50%'],
itemStyle: { // itemStyle: {
normal: { // normal: {
label: { // label: {
show: false // show: false
}, // },
labelLine: { // labelLine: {
show: false, // show: false,
length: 100, // length: 100,
smooth: 0.5 // smooth: 0.5
}, // },
borderWidth: 5, // borderWidth: 5,
shadowBlur: 40, // shadowBlur: 40,
borderColor: "#00B3FF", // borderColor: "#00B3FF",
shadowColor: 'rgba(0, 0, 0, 0)' // // shadowColor: 'rgba(0, 0, 0, 0)' //
} // }
}, // },
data: [{ // data: [{
value: 12, // value: 12,
}, { // }, {
value: 4, // value: 4,
name: '', // name: '',
itemStyle: placeHolderStyle // itemStyle: placeHolderStyle
}] // }]
}, // },
// ------------2 // // ------------2
{ // {
name: '值', // name: '',
type: 'pie', // type: 'pie',
clockWise: true, // clockWise: true,
hoverAnimation: false, // hoverAnimation: false,
radius: ['72%', '67%'], // radius: ['72%', '67%'],
center: ['50%', '50%'], // center: ['50%', '50%'],
itemStyle: { // itemStyle: {
normal: { // normal: {
label: { // label: {
show: false // show: false
}, // },
labelLine: { // labelLine: {
show: false, // show: false,
length: 100, // length: 100,
smooth: 0.5 // smooth: 0.5
}, // },
borderWidth: 5, // borderWidth: 5,
shadowBlur: 40, // shadowBlur: 40,
borderColor: "#F1E453", // borderColor: "#F1E453",
shadowColor: 'rgba(0, 0, 0, 0)' // // shadowColor: 'rgba(0, 0, 0, 0)' //
} // }
}, // },
data: [{ // data: [{
value: 6, // value: 6,
}, { // }, {
value: 4, // value: 4,
name: '', // name: '',
itemStyle: placeHolderStyle // itemStyle: placeHolderStyle
}] // }]
}, // },
// ------------3 // // ------------3
{ // {
name: '值', // name: '',
type: 'pie', // type: 'pie',
clockWise: true, // clockWise: true,
hoverAnimation: false, // hoverAnimation: false,
radius: ['48%', '44%'], // radius: ['48%', '44%'],
center: ['50%', '50%'], // center: ['50%', '50%'],
itemStyle: { // itemStyle: {
normal: { // normal: {
label: { // label: {
show: false // show: false
}, // },
labelLine: { // labelLine: {
show: false, // show: false,
length: 100, // length: 100,
smooth: 0.5 // smooth: 0.5
}, // },
borderWidth: 5, // borderWidth: 5,
shadowBlur: 40, // shadowBlur: 40,
borderColor: "#f85b60", // borderColor: "#f85b60",
shadowColor: 'rgba(0, 0, 0, 0)' // // shadowColor: 'rgba(0, 0, 0, 0)' //
} // }
}, // },
data: [{ // data: [{
value: 9, // value: 9,
}, { // }, {
value: 44, // value: 44,
name: '', // name: '',
itemStyle: placeHolderStyle // itemStyle: placeHolderStyle
}] // }]
}, // },
] // ]
}); // });
// var data = [{
myChart.dispatchAction({ type: 'highlight', seriesIndex: [0, 1, 2], dataIndex: 0 }); name: "本科及以上",
value: 13211
},
{
name: "高中",
value: 42111
},
{
name: "初中及以下",
value: 81711
},
{
name: "其他",
value: 121711
} }
];
function getArrayValue(array, key) {
var key = key || "value";
var res = [];
if (array) {
array.forEach(function(t) {
res.push(t[key]);
});
}
return res;
}
function array2obj(array,key) {
var resObj = {};
for(var i=0;i<array.length;i++){
resObj[array[i][key]] = array[i];
}
return resObj;
}
function getData(data) {
var res = {
series: [],
yAxis: []
};
for (let i = 0; i < data.length; i++) {
res.series.push({
name: '学历',
type: 'pie',
clockWise: false, //
hoverAnimation: false, //
radius: [65 - i * 15 + '%', 57 - i * 15 + '%'],
center: ["30%", "55%"],
label: {
show: false
},
itemStyle: {
label: {
show: false,
},
labelLine: {
show: false
},
borderWidth: 5,
},
data: [{
value: data[i].value,
name: data[i].name
}, {
value: sumValue - data[i].value,
name: '',
itemStyle: {
color: "rgba(0,0,0,0)",
borderWidth: 0
},
tooltip: {
show: false
},
hoverAnimation: false
}]
});
res.series.push({
name: '',
type: 'pie',
silent: true,
z: 1,
clockWise: false, //
hoverAnimation: false, //
radius: [65 - i * 15 + '%', 57 - i * 15 + '%'],
center: ["30%", "55%"],
label: {
show: false
},
itemStyle: {
label: {
show: false,
},
labelLine: {
show: false
},
borderWidth: 5,
},
data: [{
value: 7.5,
itemStyle: {
color: "#E3F0FF",
borderWidth: 0
},
tooltip: {
show: false
},
hoverAnimation: false
}, {
value: 2.5,
name: '',
itemStyle: {
color: "rgba(0,0,0,0)",
borderWidth: 0
},
tooltip: {
show: false
},
hoverAnimation: false
}]
});
res.yAxis.push((data[i].value / sumValue * 100).toFixed(2) + "%");
}
return res;
}
var arrName = getArrayValue(data, "name");
var arrValue = getArrayValue(data, "value");
var sumValue = eval(arrValue.join('+'));
var objData = array2obj(data, "name");
var optionData = getData(data);
myChart.option = {
backgroundColor:'#fff',
legend: {
show: true,
top: "center",
left: '70%',
data: arrName,
itemWidth: 30,
itemHeight: 20,
width:50,
padding: [0, 5],
itemGap: 25,
formatter: function(name) {
return "{title|" + name + "}\n{value|" + (objData[name].value) + "人}"
},
textStyle: {
rich: {
title: {
fontSize: 10,
lineHeight: 10,
color: "rgba(0,0,0,.45)"
},
value: {
fontSize: 14,
lineHeight: 18,
color: "rgba(0,0,0,.85)"
}
}
},
},
tooltip: {
show: true,
trigger: "item",
formatter: "{a}<br>{b}:{c}({d}%)"
},
color: ['#FF8700', '#ffc300', '#00e473', '#009DFF'],
grid: {
top: '20%',
bottom: '48%',
left: "30%",
containLabel: false
},
yAxis: [{
type: 'category',
inverse: true,
axisLine: {
show: false
},
axisTick: {
show: false
},
axisLabel: {
interval: 0,
inside: true,
textStyle: {
color: "#000",
fontSize: 10,
},
show: true
},
data: optionData.yAxis
}],
xAxis: [{
show: false
}],
series: optionData.series
};
//
// myChart.dispatchAction({ type: 'highlight', seriesIndex: [0, 1, 2], dataIndex: 0 });
},
} }
}; };
</script> </script>