|
|
<template>
|
|
|
<div :style="styleObj" class="percentContainer">
|
|
|
<div class="percent-item" :style="percentItemStyle" v-for="item in percentData">
|
|
|
<v-chart :options="item.options" autoresize/>
|
|
|
<div class="chart-title" :style="titleStyle">{{ item.name }}</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
var per = 60;
|
|
|
export default {
|
|
|
name: "customPiePercentageCard",//百分比图参考:https://www.makeapie.com/editor.html?c=xFkzKG-bpl
|
|
|
components: {},
|
|
|
props: {
|
|
|
value: Object,
|
|
|
ispreview: Boolean
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
percentData:'',//数据
|
|
|
angle: 0,
|
|
|
/* options: {
|
|
|
title: {
|
|
|
text: '{nums|' + per + '}{percent|%}',
|
|
|
x: 'center',
|
|
|
y: 'center',
|
|
|
textStyle: {
|
|
|
rich: {
|
|
|
nums: {
|
|
|
fontSize: 60,
|
|
|
color: '#29EEF3',
|
|
|
},
|
|
|
percent: {
|
|
|
fontSize: 30,
|
|
|
color: '#29EEF3',
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
legend: {
|
|
|
type: 'plain',
|
|
|
orient: 'vertical',
|
|
|
right: 0,
|
|
|
top: '10%',
|
|
|
align: 'auto',
|
|
|
textStyle: {
|
|
|
color: 'white',
|
|
|
fontSize: 16,
|
|
|
padding: [10, 1, 10, 0],
|
|
|
},
|
|
|
selectedMode: false,
|
|
|
},
|
|
|
series: [
|
|
|
{
|
|
|
//name: '圆环',
|
|
|
type: 'pie',
|
|
|
radius: ['58%', '45%'],
|
|
|
silent: true,
|
|
|
clockwise: false,//圆环旋转方向,逆时针/顺时针
|
|
|
startAngle: 90,
|
|
|
z: 0,
|
|
|
zlevel: 0,
|
|
|
label: {
|
|
|
normal: {
|
|
|
position: 'center',
|
|
|
},
|
|
|
},
|
|
|
itemStyle:{
|
|
|
borderColor:'#00ff00',
|
|
|
borderWidth:[0,0,0,3],
|
|
|
borderType :'solid',
|
|
|
},
|
|
|
data: [
|
|
|
{
|
|
|
value: per,
|
|
|
name: '',
|
|
|
itemStyle: {
|
|
|
normal: {
|
|
|
color: {
|
|
|
// 完成的圆环的颜色
|
|
|
colorStops: [
|
|
|
{
|
|
|
offset: 0,
|
|
|
color: '#4FADFD', // 0% 处的颜色
|
|
|
},
|
|
|
{
|
|
|
offset: 1,
|
|
|
color: '#28E8FA', // 100% 处的颜色
|
|
|
},
|
|
|
],
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
value: 100 - per,
|
|
|
name: '',
|
|
|
label: {
|
|
|
normal: {
|
|
|
show: false,
|
|
|
},
|
|
|
},
|
|
|
//剩余圆环颜色
|
|
|
itemStyle: {
|
|
|
normal: {
|
|
|
color: '#173164',
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
],
|
|
|
},
|
|
|
],
|
|
|
},*/
|
|
|
optionsStyle: {}, // 样式
|
|
|
optionsData: {}, // 数据
|
|
|
optionsCollapse: {}, // 图标属性
|
|
|
optionsSetup: {}
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
|
styleObj() {
|
|
|
return {
|
|
|
position: this.ispreview ? "absolute" : "static",
|
|
|
width: this.optionsStyle.width + "px",
|
|
|
height: this.optionsStyle.height + "px",
|
|
|
left: this.optionsStyle.left + "px",
|
|
|
top: this.optionsStyle.top + "px",
|
|
|
background: this.optionsSetup.background,
|
|
|
'flex-flow':this.optionsSetup.flexFlow
|
|
|
};
|
|
|
},
|
|
|
//环形图样式
|
|
|
percentItemStyle(){
|
|
|
let length=this.percentData.length;
|
|
|
let widthCirle=this.optionsSetup.flexFlow=='column'?this.optionsStyle.height:this.optionsStyle.width;
|
|
|
let num=this.optionsSetup.flexFlow=='column'?60:20;
|
|
|
let width=widthCirle/length-20//+100;
|
|
|
return {
|
|
|
width: width + "px",
|
|
|
height: width + "px",
|
|
|
}
|
|
|
},
|
|
|
//下标题样式
|
|
|
titleStyle(){
|
|
|
return{
|
|
|
'font-size':this.optionsSetup.textFontSize+'px',
|
|
|
color: this.optionsSetup.textColor,
|
|
|
'font-weight': this.optionsSetup.textFontWeight
|
|
|
}
|
|
|
}
|
|
|
|
|
|
},
|
|
|
watch: {
|
|
|
value: {
|
|
|
handler(val) {
|
|
|
this.optionsStyle = val.position;
|
|
|
this.optionsData = val.data;
|
|
|
this.optionsCollapse = val.collapse;
|
|
|
this.optionsSetup = val.setup;
|
|
|
this.editorOptions();
|
|
|
},
|
|
|
deep: true
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
|
this.optionsStyle = this.value.position;
|
|
|
this.optionsData = this.value.data;
|
|
|
this.optionsCollapse = this.value.collapse;
|
|
|
this.optionsSetup = this.value.setup;
|
|
|
this.editorOptions();
|
|
|
},
|
|
|
mounted() {
|
|
|
/* setInterval(() => {
|
|
|
this.angle = this.angle + 3
|
|
|
myChart.setOption(options,true)
|
|
|
}, 1000);*/
|
|
|
},
|
|
|
methods: {
|
|
|
//轴point设置
|
|
|
getCirlPoint(x0, y0, r, x) {
|
|
|
let x1 = x0 + r * Math.cos((x * Math.PI) / 180);
|
|
|
let y1 = y0 + r * Math.sin((x * Math.PI) / 180);
|
|
|
return {
|
|
|
x: x1,
|
|
|
y: y1,
|
|
|
};
|
|
|
},
|
|
|
editorOptions() {
|
|
|
this.setOptionsData();
|
|
|
this.setOptionsTitle();
|
|
|
this.setOptionsColor();
|
|
|
this.setOptionSurplusColor();
|
|
|
},
|
|
|
setOptionsTitle() {
|
|
|
const optionsSetup = this.optionsSetup;
|
|
|
this.percentData.map(item=>{
|
|
|
const title = item.options.title;
|
|
|
title.x = "center";
|
|
|
title.y = "center";
|
|
|
const rich = {
|
|
|
nums: {
|
|
|
fontSize: optionsSetup.textNumFontSize,
|
|
|
color: optionsSetup.isCircleColor?item.num<60?optionsSetup.color0Start:item.num<90?optionsSetup.color0Start90:optionsSetup.color0Start100: optionsSetup.textNumColor,
|
|
|
fontWeight: optionsSetup.textNumFontWeight
|
|
|
},
|
|
|
percent: {
|
|
|
fontSize: optionsSetup.textPerFontSize,
|
|
|
color: optionsSetup.isCircleColor?item.num<60?optionsSetup.color0Start:item.num<90?optionsSetup.color0Start90:optionsSetup.color0Start100:optionsSetup.textPerColor,
|
|
|
fontWeight: optionsSetup.textPerFontWeight
|
|
|
}
|
|
|
};
|
|
|
title.textStyle['rich'] = rich;
|
|
|
item.options.title = title;
|
|
|
})
|
|
|
},
|
|
|
//圆环0-100%颜色
|
|
|
setOptionsColor() {
|
|
|
const optionsSetup = this.optionsSetup;
|
|
|
this.percentData.map(item=>{
|
|
|
const itemStyle = item.options.series[0]['data'][0]['itemStyle']
|
|
|
const normal = {
|
|
|
color: {
|
|
|
// 完成的圆环的颜色
|
|
|
colorStops: [
|
|
|
{
|
|
|
offset: 0,
|
|
|
color: item.num<60?optionsSetup.color0Start:item.num<90?optionsSetup.color0Start90:optionsSetup.color0Start100, // 0% 处的颜色
|
|
|
},
|
|
|
{
|
|
|
offset: 1,
|
|
|
color: item.num<60?optionsSetup.color100End:item.num<90?optionsSetup.color100End90:optionsSetup.color100End100, // 100% 处的颜色
|
|
|
},
|
|
|
],
|
|
|
},
|
|
|
};
|
|
|
itemStyle['normal'] = normal;
|
|
|
})
|
|
|
|
|
|
},
|
|
|
setOptionSurplusColor() {
|
|
|
this.percentData.map(item=>{
|
|
|
const itemStyle = item.options.series[0]['data'][1]['itemStyle']
|
|
|
const normal = {
|
|
|
color: this.optionsSetup.colorsurplus,
|
|
|
};
|
|
|
itemStyle['normal'] = normal
|
|
|
})
|
|
|
|
|
|
},
|
|
|
// 数据解析
|
|
|
setOptionsData() {
|
|
|
const optionsData = this.optionsData; // 数据类型 静态 or 动态
|
|
|
optionsData.dataType == "staticData"
|
|
|
? this.staticDataFn(optionsData.staticData)
|
|
|
: this.dynamicDataFn(
|
|
|
optionsData.dynamicData,
|
|
|
optionsData.refreshTime
|
|
|
);
|
|
|
},
|
|
|
setOptionsInfo(){
|
|
|
return {
|
|
|
title: {
|
|
|
text: '{nums|' + per + '}{percent|%}',
|
|
|
x: 'center',
|
|
|
y: 'center',
|
|
|
textStyle: {
|
|
|
rich: {
|
|
|
nums: {
|
|
|
fontSize: 60,
|
|
|
color: '#29EEF3',
|
|
|
},
|
|
|
percent: {
|
|
|
fontSize: 30,
|
|
|
color: '#29EEF3',
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
legend: {
|
|
|
type: 'plain',
|
|
|
orient: 'vertical',
|
|
|
right: 0,
|
|
|
top: '10%',
|
|
|
align: 'auto',
|
|
|
textStyle: {
|
|
|
color: 'white',
|
|
|
fontSize: 16,
|
|
|
padding: [10, 1, 10, 0],
|
|
|
},
|
|
|
selectedMode: false,
|
|
|
},
|
|
|
series: [
|
|
|
{
|
|
|
//name: '圆环',
|
|
|
type: 'pie',
|
|
|
radius: ['85%', '73%'],
|
|
|
silent: true,
|
|
|
clockwise: false,//圆环旋转方向,逆时针/顺时针
|
|
|
startAngle: 90,
|
|
|
z: 0,
|
|
|
zlevel: 0,
|
|
|
label: {
|
|
|
normal: {
|
|
|
position: 'center',
|
|
|
},
|
|
|
},
|
|
|
itemStyle:{
|
|
|
borderColor:'#00ff00',
|
|
|
borderWidth:[0,0,0,3],
|
|
|
borderType :'solid',
|
|
|
},
|
|
|
data: [
|
|
|
{
|
|
|
value: per,
|
|
|
name: '',
|
|
|
itemStyle: {
|
|
|
normal: {
|
|
|
color: {
|
|
|
// 完成的圆环的颜色
|
|
|
colorStops: [
|
|
|
{
|
|
|
offset: 0,
|
|
|
color: '#4FADFD', // 0% 处的颜色
|
|
|
},
|
|
|
{
|
|
|
offset: 1,
|
|
|
color: '#28E8FA', // 100% 处的颜色
|
|
|
},
|
|
|
],
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
value: 100 - per,
|
|
|
name: '',
|
|
|
label: {
|
|
|
normal: {
|
|
|
show: false,
|
|
|
},
|
|
|
},
|
|
|
//剩余圆环颜色
|
|
|
itemStyle: {
|
|
|
normal: {
|
|
|
color: '#173164',
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
],
|
|
|
},
|
|
|
]
|
|
|
}
|
|
|
},
|
|
|
staticDataFn(val) {
|
|
|
this.percentData=val;
|
|
|
let length=this.percentData.length;
|
|
|
let optionsArr=[];
|
|
|
this.percentData.map((item,index)=>{
|
|
|
item.options=this.setOptionsInfo();
|
|
|
item.options.title.text= '{nums|' + item.num + '}{percent|%}';
|
|
|
item.options.series.map(v=>{
|
|
|
v.data[0]['value'] = item.num;
|
|
|
v.data[1]['value'] = 100-item.num;
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
dynamicDataFn(val, refreshTime) {
|
|
|
if (!val) return;
|
|
|
if (this.ispreview) {
|
|
|
this.getEchartData(val);
|
|
|
this.flagInter = setInterval(() => {
|
|
|
this.getEchartData(val);
|
|
|
}, refreshTime);
|
|
|
} else {
|
|
|
this.getEchartData(val);
|
|
|
}
|
|
|
},
|
|
|
getEchartData(val) {
|
|
|
const data = this.queryEchartsData(val);
|
|
|
data.then(res => {
|
|
|
this.percentData=res;
|
|
|
let length=this.percentData.length;
|
|
|
let optionsArr=[];
|
|
|
this.percentData.map((item,index)=>{
|
|
|
item.options=this.setOptionsInfo();
|
|
|
item.options.title.text= '{nums|' + item.num + '}{percent|%}';
|
|
|
item.options.series.map(v=>{
|
|
|
v.data[0]['value'] = item.num;
|
|
|
v.data[1]['value'] = 100-item.num;
|
|
|
})
|
|
|
})
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
.echarts {
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
|
overflow: hidden;
|
|
|
}
|
|
|
.percentContainer{
|
|
|
box-sizing: content-box;
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
|
justify-content: space-around;
|
|
|
}
|
|
|
.percent-item{
|
|
|
width:100%;height:100%;
|
|
|
margin:10px;
|
|
|
position: relative;
|
|
|
}
|
|
|
.chart-title{
|
|
|
/* position: absolute;
|
|
|
left: 0;
|
|
|
right:0;
|
|
|
bottom:20px;*/
|
|
|
}
|
|
|
</style> |
...
|
...
|
|