This commit is contained in:
chengdandan 2023-03-23 10:29:36 +08:00
parent 9a6486a8a5
commit eb8be78cfe
1 changed files with 96 additions and 292 deletions

View File

@ -101,323 +101,127 @@ export default {
initCharts() {
let myChart = this.$echarts.init(this.$refs.chart);
// var placeHolderStyle = {
// normal: {
// label: {
// show: false,
// position: "center"
// },
// labelLine: {
// show: false
// },
// color: "#104841a3",
// borderWidth: 0
// },
// emphasis: {
// color: "#104841a3",
// borderColor: "#00b3ff",
// borderWidth: 0
// }
// };
// //
// myChart.setOption({
// series: [
// {
// name: '',
// type: 'pie',
// clockWise: true,
// hoverAnimation: false,
// radius: ['92%', '97%'],
// center: ['50%', '50%'],
// itemStyle: {
// normal: {
// label: {
// show: false
// },
// labelLine: {
// show: false,
// length: 100,
// smooth: 0.5
// },
// borderWidth: 5,
// shadowBlur: 40,
// borderColor: "#00B3FF",
// shadowColor: 'rgba(0, 0, 0, 0)' //
// }
// },
// data: [{
// value: 12,
// }, {
// value: 4,
// name: '',
// itemStyle: placeHolderStyle
// }]
// },
// // ------------2
// {
// name: '',
// type: 'pie',
// clockWise: true,
// hoverAnimation: false,
// radius: ['72%', '67%'],
// center: ['50%', '50%'],
// itemStyle: {
// normal: {
// label: {
// show: false
// },
// labelLine: {
// show: false,
// length: 100,
// smooth: 0.5
// },
// borderWidth: 5,
// shadowBlur: 40,
// borderColor: "#F1E453",
// shadowColor: 'rgba(0, 0, 0, 0)' //
// }
// },
// data: [{
// value: 6,
// }, {
// value: 4,
// name: '',
// itemStyle: placeHolderStyle
// }]
// },
// // ------------3
// {
// name: '',
// type: 'pie',
// clockWise: true,
// hoverAnimation: false,
// radius: ['48%', '44%'],
// center: ['50%', '50%'],
// itemStyle: {
// normal: {
// label: {
// show: false
// },
// labelLine: {
// show: false,
// length: 100,
// smooth: 0.5
// },
// borderWidth: 5,
// shadowBlur: 40,
// borderColor: "#f85b60",
// shadowColor: 'rgba(0, 0, 0, 0)' //
// }
// },
// data: [{
// value: 9,
// }, {
// value: 44,
// name: '',
// itemStyle: placeHolderStyle
// }]
// },
// ]
// });
var data = [{
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: '学历',
var placeHolderStyle = {
normal: {
label: {
show: false,
position: "center"
},
labelLine: {
show: false
},
color: "#104841a3",
borderWidth: 0
},
emphasis: {
color: "#104841a3",
borderColor: "#00b3ff",
borderWidth: 0
}
};
//
myChart.setOption({
series: [
{
name: '值',
type: 'pie',
clockWise: false, //
hoverAnimation: false, //
radius: [65 - i * 15 + '%', 57 - i * 15 + '%'],
center: ["30%", "55%"],
label: {
show: false
},
clockWise: true,
hoverAnimation: false,
radius: ['92%', '97%'],
center: ['50%', '50%'],
itemStyle: {
normal: {
label: {
show: false,
show: false
},
labelLine: {
show: false
show: false,
length: 100,
smooth: 0.5
},
borderWidth: 5,
shadowBlur: 40,
borderColor: "#00B3FF",
shadowColor: 'rgba(0, 0, 0, 0)' //
}
},
data: [{
value: data[i].value,
name: data[i].name
value: 12,
}, {
value: sumValue - data[i].value,
name: '',
itemStyle: {
color: "rgba(0,0,0,0)",
borderWidth: 0
},
tooltip: {
show: false
},
hoverAnimation: false
value: 4,
name: '',
itemStyle: placeHolderStyle
}]
});
res.series.push({
name: '',
},
// ------------2
{
name: '值',
type: 'pie',
silent: true,
z: 1,
clockWise: false, //
hoverAnimation: false, //
radius: [65 - i * 15 + '%', 57 - i * 15 + '%'],
center: ["30%", "55%"],
label: {
show: false
},
clockWise: true,
hoverAnimation: false,
radius: ['72%', '67%'],
center: ['50%', '50%'],
itemStyle: {
normal: {
label: {
show: false,
show: false
},
labelLine: {
show: false
show: false,
length: 100,
smooth: 0.5
},
borderWidth: 5,
shadowBlur: 40,
borderColor: "#F1E453",
shadowColor: 'rgba(0, 0, 0, 0)' //
}
},
data: [{
value: 7.5,
itemStyle: {
color: "#E3F0FF",
borderWidth: 0
},
tooltip: {
show: false
},
hoverAnimation: false
value: 6,
}, {
value: 2.5,
name: '',
itemStyle: {
color: "rgba(0,0,0,0)",
borderWidth: 0
},
tooltip: {
show: false
},
hoverAnimation: false
value: 4,
name: '',
itemStyle: placeHolderStyle
}]
});
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)"
},
// ------------3
{
name: '值',
type: 'pie',
clockWise: true,
hoverAnimation: false,
radius: ['48%', '44%'],
center: ['50%', '50%'],
itemStyle: {
normal: {
label: {
show: false
},
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,
labelLine: {
show: false,
length: 100,
smooth: 0.5
},
borderWidth: 5,
shadowBlur: 40,
borderColor: "#f85b60",
shadowColor: 'rgba(0, 0, 0, 0)' //
}
},
show: true
},
data: optionData.yAxis
}],
xAxis: [{
show: false
}],
series: optionData.series
};
data: [{
value: 9,
}, {
value: 44,
name: '',
itemStyle: placeHolderStyle
}]
},
]
});
//
// myChart.dispatchAction({ type: 'highlight', seriesIndex: [0, 1, 2], dataIndex: 0 });
myChart.dispatchAction({ type: 'highlight', seriesIndex: [0, 1, 2], dataIndex: 0 });
},
}