Authored by 鲁尚清

自定义卡片圆环百分比组件及配置,自定义圆环内边框百分比组件及配置

/*
* @Descripttion: 百分比图 json
* @version:
* @Author: lsq
* @Date: 2022-03-04
* @LastEditors: lsq
* @LastEditTime: 2022-03-04
*/
export const monitorCustomPiePercentageBorder = {
code: 'monitor-custom-pie-percentage-border',
type: 'chart',
label: '百分比图-内边框',
icon: 'iconbaifenbi',
options: {
// 配置
setup: [
{
type: 'el-input-text',
label: '图层名称',
name: 'layerName',
required: false,
placeholder: '',
value: '百分比图',
},
{
type: 'vue-color',
label: '背景颜色',
name: 'background',
required: false,
placeholder: '',
value: ''
},
[
{
name: '内圆形边框设置',
list: [
{
type: 'vue-color',
label: '边框颜色',
name: 'customBorderColor',
required: false,
placeholder: '',
value: '#4FADFD'
},
{
type: 'el-input-number',
label: '边框宽度',
name: 'lineWidth',
required: false,
placeholder: '',
value: '1.5'
},
]
},
{
name: '数值设置',
list: [
{
type: 'vue-color',
label: '数值颜色',
name: 'textNumColor',
required: false,
placeholder: '',
value: '#666'
},
{
type: 'el-input-number',
label: '数值字体',
name: 'textNumFontSize',
required: false,
placeholder: '',
value: 40
},
{
type: 'el-select',
label: '字体粗细',
name: 'textNumFontWeight',
required: false,
placeholder: '',
selectOptions: [
{code: 'normal', name: '正常'},
{code: 'bold', name: '粗体'},
{code: 'bolder', name: '特粗体'},
{code: 'lighter', name: '细体'}
],
value: 'normal'
},
{
type: 'vue-color',
label: '%号颜色',
name: 'textPerColor',
required: false,
placeholder: '',
value: '#666'
},
{
type: 'el-input-number',
label: '%号字体',
name: 'textPerFontSize',
required: false,
placeholder: '',
value: 20
},
{
type: 'el-select',
label: '字体粗细',
name: 'textPerFontWeight',
required: false,
placeholder: '',
selectOptions: [
{code: 'normal', name: '正常'},
{code: 'bold', name: '粗体'},
{code: 'bolder', name: '特粗体'},
{code: 'lighter', name: '细体'}
],
value: 'normal'
}
],
},
/* {
name: '圆环设置',
list: [
{
type: 'el-input-number',
label: '刻度数量',
name: 'lineNumber',
required: false,
placeholder: '',
value: 0
},
{
type: 'el-input-number',
label: '刻度长度',
name: 'lineLength',
required: false,
placeholder: '',
value: 0
},
{
type: 'el-input-number',
label: '刻度宽度',
name: 'lineWidth',
required: false,
placeholder: '',
value: 2
},
{
type: 'vue-color',
label: '刻度颜色',
name: 'lineColor',
required: false,
placeholder: '',
value: '#061740'
},
]
},*/
{
name: '渐变色',
list: [
{
type: 'vue-color',
label: '0%处颜色',
name: 'color0Start',
required: false,
placeholder: '',
value: '#4FADFD'
},
{
type: 'vue-color',
label: '100%颜色',
name: 'color100End',
required: false,
placeholder: '',
value: '#28E8FA'
},
{
type: 'vue-color',
label: '余处颜色',
name: 'colorsurplus',
required: false,
placeholder: '',
value: '#bfcff0'
},
]
}
],
],
// 数据
data: [
{
type: 'el-radio-group',
label: '数据类型',
name: 'dataType',
require: false,
placeholder: '',
selectValue: true,
selectOptions: [
{
code: 'staticData',
name: '静态数据',
},
{
code: 'dynamicData',
name: '动态数据',
},
],
value: 'staticData',
},
{
type: 'el-input-number',
label: '刷新时间(毫秒)',
name: 'refreshTime',
relactiveDom: 'dataType',
relactiveDomValue: 'dynamicData',
value: 5000
},
{
type: 'el-button',
label: '静态数据',
name: 'staticData',
required: false,
placeholder: '',
relactiveDom: 'dataType',
relactiveDomValue: 'staticData',
value: [
{"num":60,"name":'cpu容量'},{"num":70,"name":'存储容量'}
],
},
{
type: 'dycustComponents',
label: '',
name: 'dynamicData',
required: false,
placeholder: '',
relactiveDom: 'dataType',
chartType: 'widget-piechart',
dictKey: 'TEXT_PROPERTIES',
relactiveDomValue: 'dynamicData',
value: '',
},
],
// 坐标
position: [
{
type: 'el-input-number',
label: '左边距',
name: 'left',
required: false,
placeholder: '',
value: 0,
},
{
type: 'el-input-number',
label: '上边距',
name: 'top',
required: false,
placeholder: '',
value: 0,
},
{
type: 'el-input-number',
label: '宽度',
name: 'width',
required: false,
placeholder: '该容器在1920px大屏中的宽度',
value: 400,
},
{
type: 'el-input-number',
label: '高度',
name: 'height',
required: false,
placeholder: '该容器在1080px大屏中的高度',
value: 300,
},
],
}
}
... ...
/*
* @Descripttion: 百分比图 json
* @version:
* @Author: lsq
* @Date: 2022-03-04
* @LastEditors: lsq
* @LastEditTime: 2022-03-04
*/
export const monitorCustomPiePercentageCard = {
code: 'monitor-custom-pie-percentage-card',
type: 'chart',
label: '百分比图-卡片',
icon: 'iconbaifenbi',
options: {
// 配置
setup: [
{
type: 'el-input-text',
label: '图层名称',
name: 'layerName',
required: false,
placeholder: '',
value: '百分比图',
},
{
type: 'vue-color',
label: '背景颜色',
name: 'background',
required: false,
placeholder: '',
value: ''
},
{
type: 'el-select',
label: '显示',
name: 'flexFlow',
required: false,
placeholder: '',
selectOptions: [
{code: 'row', name: '横排'},
{code: 'column', name: '竖排'},
],
value: 'row'
},
[
{
name: '进度条设置',
list: [
{
type: 'el-switch',
label: '进度条文字显示',
name: 'showText',
required: false,
placeholder: '',
value: true,
},
{
type: 'el-switch',
label: '文字显示在内',
name: 'textInside',
required: false,
placeholder: '',
value: false,
},
{
type: 'el-input-number',
label: '进度条宽度',
name: 'progressWidth',
required: false,
placeholder: '',
value: 16
},
{
type: 'el-input-number',
label: '字体大小',
name: 'progressFontSize',
required: false,
placeholder: '',
value: '16'
},
{
type: 'vue-color',
label: '字体颜色',
name: 'progressColor',
required: false,
placeholder: '',
value: '#666'
},
{
type: 'el-select',
label: '字体粗细',
name: 'progressFontWeight',
required: false,
placeholder: '',
selectOptions: [
{code: 'normal', name: '正常'},
{code: 'bold', name: '粗体'},
{code: 'bolder', name: '特粗体'},
{code: 'lighter', name: '细体'}
],
value: 'normal'
},
{
type: 'vue-color',
label: '60%以下颜色',
name: 'progressColorGood',
required: false,
placeholder: '',
value: '#24ca3c'
},
{
type: 'vue-color',
label: '90%以下颜色',
name: 'progressColorWorse',
required: false,
placeholder: '',
value: '#fbb248'
},
{
type: 'vue-color',
label: '90%以上颜色',
name: 'progressColorWorst',
required: false,
placeholder: '',
value: '#ec3839'
},
]
},
{
name: '数值设置',
list: [
{
type: 'el-switch',
label: '颜色取值圆环',
name: 'isCircleColor',
required: false,
placeholder: '',
value: true,
},
{
type: 'vue-color',
label: '数值颜色',
name: 'textNumColor',
required: false,
placeholder: '',
value: '#666'
},
{
type: 'el-input-number',
label: '数值字体',
name: 'textNumFontSize',
required: false,
placeholder: '',
value: 40
},
{
type: 'el-select',
label: '字体粗细',
name: 'textNumFontWeight',
required: false,
placeholder: '',
selectOptions: [
{code: 'normal', name: '正常'},
{code: 'bold', name: '粗体'},
{code: 'bolder', name: '特粗体'},
{code: 'lighter', name: '细体'}
],
value: 'normal'
},
{
type: 'vue-color',
label: '%号颜色',
name: 'textPerColor',
required: false,
placeholder: '',
value: '#666'
},
{
type: 'el-input-number',
label: '%号字体',
name: 'textPerFontSize',
required: false,
placeholder: '',
value: 20
},
{
type: 'el-select',
label: '字体粗细',
name: 'textPerFontWeight',
required: false,
placeholder: '',
selectOptions: [
{code: 'normal', name: '正常'},
{code: 'bold', name: '粗体'},
{code: 'bolder', name: '特粗体'},
{code: 'lighter', name: '细体'}
],
value: 'normal'
}
],
},
{
name: '渐变色',
list: [
{
type: 'vue-color',
label: '0%处小于60颜色',
name: 'color0Start',
required: false,
placeholder: '',
value: '#24ca3c'
},
{
type: 'vue-color',
label: '100%处小于60颜色',
name: 'color100End',
required: false,
placeholder: '',
value: '#b0f6ba'
},
{
type: 'vue-color',
label: '0%处小于90颜色',
name: 'color0Start90',
required: false,
placeholder: '',
value: '#fbb248'
},
{
type: 'vue-color',
label: '100%处小于90颜色',
name: 'color100End90',
required: false,
placeholder: '',
value: '#eec990'
},
{
type: 'vue-color',
label: '0%处大于90颜色',
name: 'color0Start100',
required: false,
placeholder: '',
value: '#ec3839'
},
{
type: 'vue-color',
label: '100%处大于90颜色',
name: 'color100End100',
required: false,
placeholder: '',
value: '#fd8585'
},
{
type: 'vue-color',
label: '余处颜色',
name: 'colorsurplus',
required: false,
placeholder: '',
value: 'rgba(191, 207, 240, 0.6)'
},
]
},
{
name: '下标题设置',
list: [
{
type: 'vue-color',
label: '文字颜色',
name: 'textColor',
required: false,
placeholder: '',
value: '#666'
},
{
type: 'el-input-number',
label: '文字字体',
name: 'textFontSize',
required: false,
placeholder: '',
value: 14
},
{
type: 'el-select',
label: '字体粗细',
name: 'textFontWeight',
required: false,
placeholder: '',
selectOptions: [
{code: 'normal', name: '正常'},
{code: 'bold', name: '粗体'},
{code: 'bolder', name: '特粗体'},
{code: 'lighter', name: '细体'}
],
value: 'normal'
}
],
}
],
],
// 数据
data: [
{
type: 'el-radio-group',
label: '数据类型',
name: 'dataType',
require: false,
placeholder: '',
selectValue: true,
selectOptions: [
{
code: 'staticData',
name: '静态数据',
},
{
code: 'dynamicData',
name: '动态数据',
},
],
value: 'staticData',
},
{
type: 'el-input-number',
label: '刷新时间(毫秒)',
name: 'refreshTime',
relactiveDom: 'dataType',
relactiveDomValue: 'dynamicData',
value: 5000
},
{
type: 'el-button',
label: '静态数据',
name: 'staticData',
required: false,
placeholder: '',
relactiveDom: 'dataType',
relactiveDomValue: 'staticData',
value: [
{"num":50,"name":'cpu容量'},{"num":70,"name":'内存容量'},{"num":90,"name":'存储容量'}
],
},
{
type: 'dycustComponents',
label: '',
name: 'dynamicData',
required: false,
placeholder: '',
relactiveDom: 'dataType',
chartType: 'widget-piechart',
dictKey: 'TEXT_PROPERTIES',
relactiveDomValue: 'dynamicData',
value: '',
},
],
// 坐标
position: [
{
type: 'el-input-number',
label: '左边距',
name: 'left',
required: false,
placeholder: '',
value: 0,
},
{
type: 'el-input-number',
label: '上边距',
name: 'top',
required: false,
placeholder: '',
value: 0,
},
{
type: 'el-input-number',
label: '宽度',
name: 'width',
required: false,
placeholder: '该容器在1920px大屏中的宽度',
value: 500,
},
{
type: 'el-input-number',
label: '高度',
name: 'height',
required: false,
placeholder: '该容器在1080px大屏中的高度',
value: 220,
},
],
}
}
... ...
... ... @@ -49,6 +49,8 @@ import {monitorButtonGroup} from "./echartsConfigJson/monitorConfigJson/monitor-
import {monitorCustomLineTrend} from "./echartsConfigJson/monitorConfigJson/monitor-custom-line-trend";
import {monitorCustomLiquidFillChart} from "./echartsConfigJson/monitorConfigJson/monitor-custom-liquid-Fill-chart";
import {monitorProgressInformation} from "./echartsConfigJson/monitorConfigJson/monitor-progress-information";
import {monitorCustomPiePercentageCard} from "./echartsConfigJson/monitorConfigJson/monitor-custom-pie-percentage-card";
import {monitorCustomPiePercentageBorder} from "./echartsConfigJson/monitorConfigJson/monitor-custom-pie-percentage-border";
export const {widgetTool,monitor} = {
... ... @@ -111,6 +113,10 @@ export const {widgetTool,monitor} = {
//水球
monitorCustomLiquidFillChart,
//进度条
monitorProgressInformation
monitorProgressInformation,
//卡片 百分比图
monitorCustomPiePercentageCard,
//百分比-内边框
monitorCustomPiePercentageBorder
]
}
... ...
<template>
<div :style="styleObj">
<!-- <div class="percent-item" :style="percentItemStyle" v-for="item in percentData">-->
<v-chart :options="options" autoresize/>
<!-- <div class="chart-title">cpu容量</div>-->
<!-- </div>-->
</div>
</template>
<script>
var per = 60;
export default {
name: "customPiePercentageBorder",//百分比图参考: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',
},
},
},
/* borderColor:'#ff0000',
borderWidth:3,
borderType :'solid',
borderRadius:5*/
},
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',
},
},
},
],
},
{
type: 'custom',
coordinateSystem: 'none',
renderItem: (params, api) => {
return {
type: 'arc',
shape: {
cx: api.getWidth() / 2,
cy: api.getHeight() / 2,
r: (Math.min(api.getWidth(), api.getHeight()) / 2) * 0.35,
startAngle: ((0 + this.angle) * Math.PI) / 180,
endAngle: ((360 + this.angle) * Math.PI) / 180,
},
style: {
stroke: this.optionsSetup.customBorderColor,
fill: 'transparent',
lineWidth: this.optionsSetup.lineWidth,
},
silent: true,
};
},
data: [0],
}
],
},
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
};
},
//内边框样式
customBorderColorStyle(){
let color=this.optionsSetup.customBorderColor?this.optionsSetup.customBorderColor:'transparent'
return{
color:color
}
},
},
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.setOptionsTitle();
this.setOptionsColor();
this.setOptionsData();
// this.setOptionLine();
this.setOptionSurplusColor();
},
setOptionsTitle() {
const optionsSetup = this.optionsSetup;
const title = this.options.title;
title.x = "center";
title.y = "center";
const rich = {
nums: {
fontSize: optionsSetup.textNumFontSize,
color: optionsSetup.textNumColor,
fontWeight: optionsSetup.textNumFontWeight
},
percent: {
fontSize: optionsSetup.textPerFontSize,
color: optionsSetup.textPerColor,
fontWeight: optionsSetup.textPerFontWeight
}
};
title.textStyle['rich'] = rich;
this.options.title = title;
},
//圆环0-100%颜色
setOptionsColor() {
const optionsSetup = this.optionsSetup;
const itemStyle = this.options.series[0]['data'][0]['itemStyle']
const normal = {
color: {
// 完成的圆环的颜色
colorStops: [
{
offset: 0,
color: optionsSetup.color0Start, // 0% 处的颜色
},
{
offset: 1,
color: optionsSetup.color100End, // 100% 处的颜色
},
],
},
};
itemStyle['normal'] = normal
},
setOptionSurplusColor() {
const itemStyle = this.options.series[0]['data'][1]['itemStyle']
const normal = {
color: this.optionsSetup.colorsurplus,
};
itemStyle['normal'] = normal
},
setOptionLine() {
// const optionsSetup = this.optionsSetup;
// const line = this.options.series[1]['splitLine'];
// const num = this.options.series[1];
// num.splitNumber = optionsSetup.lineNumber;
// line.length = optionsSetup.lineLength;
// const lineStyle = {
// width: optionsSetup.lineWidth,
// color: optionsSetup.lineColor,
// };
// line['lineStyle'] = lineStyle
},
// 数据解析
setOptionsData() {
const optionsData = this.optionsData; // 数据类型 静态 or 动态
optionsData.dataType == "staticData"
? this.staticDataFn(optionsData.staticData)
: this.dynamicDataFn(
optionsData.dynamicData,
optionsData.refreshTime
);
},
staticDataFn(val) {
const title = this.options.title;
const num = val[0]['num'];
title.text = '{nums|' + num + '}{percent|%}';
this.options.series[0]['data'][0]['value'] = num;
this.options.series[0]['data'][1]['value'] = 100 - 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.options.title.text = '{nums|' + res[0].value + '}{percent|%}';
this.options.series[0]['data'][0]['value'] = res[0].value;
this.options.series[0]['data'][1]['value'] = 100 - res[0].value;
});
}
}
};
</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;
}
</style>
... ...
<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>
... ...
... ... @@ -52,6 +52,8 @@ import monitorButtonGroup from "./monitor/buttonGroup";
import monitorCustomLineTrend from "./monitor/customLineTrend";
import monitorCustomLiquidFillChart from "./monitor/customLiquidFillChart";
import monitorProgressInformation from "./monitor/progressInformation";
import monitorCustomPiePercentageCard from "./monitor/customPiePercentageCard";
import monitorCustomPiePercentageBorder from "./monitor/customPiePercentageBorder";
export default {
name: "WidgetTemp",
... ... @@ -96,7 +98,9 @@ export default {
monitorButtonGroup,
monitorCustomLineTrend,
monitorCustomLiquidFillChart,
monitorProgressInformation
monitorProgressInformation,
monitorCustomPiePercentageCard,
monitorCustomPiePercentageBorder
},
model: {
prop: "value",
... ...
... ... @@ -63,6 +63,8 @@ import monitorButtonGroup from "./monitor/buttonGroup";
import monitorCustomLineTrend from "./monitor/customLineTrend";
import monitorCustomLiquidFillChart from "./monitor/customLiquidFillChart";
import monitorProgressInformation from "./monitor/progressInformation";
import monitorCustomPiePercentageCard from "./monitor/customPiePercentageCard";
import monitorCustomPiePercentageBorder from "./monitor/customPiePercentageBorder";
export default {
name: "Widget",
... ... @@ -106,7 +108,9 @@ export default {
monitorButtonGroup,
monitorCustomLineTrend,
monitorCustomLiquidFillChart,
monitorProgressInformation
monitorProgressInformation,
monitorCustomPiePercentageCard,
monitorCustomPiePercentageBorder
},
model: {
prop: "value",
... ...