mkl_power_box/components/norm-pie.js

159 lines
5.1 KiB
JavaScript

/**
* 顶部header
*/
Vue.component("norm-pie", {
template: `
<div style="height: 190px" ref="chart"> </div>
`,
props: {
value:{
type:Number
},
text:{
type:String
}
},
data() {
return {
option:{}
}
},
mounted(){
this.init()
},
methods: {
init(){
this.getChartData()
},
//分类及工时情况
getChartData(){
var chChartBar = echarts.init(this.$refs.chart);
this.echartBar(chChartBar,this.value,this.text)
},
echartBar(chChart,value,text){
let newPromise = new Promise((resolve) => {
resolve()
})
//然后异步执行echarts的初始化函数
newPromise.then(() => {
var placeHolderStyle = {
normal: {
label: {
show: false,
},
labelLine: {
show: false,
},
color: "rgba(0,0,0,0)",
borderWidth: 0,
},
emphasis: {
color: "rgba(0,0,0,0)",
borderWidth: 0,
},
};
var dataStyle = {
};
this.option ={
title: [
{
text: value+'%',
textAlign: "center",
left: "48%",
top: "39%",
textStyle: {
color: "#67abf2",
fontSize: 23,
},
},
{
text: text,
left: "48%",
top: "85%",
textAlign: "center",
textStyle: {
color: "#cdd7fa",
fontWeight: "normal",
fontSize: "16",
textAlign: "center",
},
},
],
series: [
{
type: "pie",
hoverAnimation: false,
radius: ["50%", "49%"],
center: ["50%", "45%"],
labelLine: {
normal: {
show: false,
},
},
label: {
normal: {
position: "center",
},
},
data: [
{
value: 100,
itemStyle: {
normal: {
color: "#255788",
},
},
},
],
},
{
type: "pie",
hoverAnimation: false,
radius: ["43%", "50%"],
center: ["50%", "45%"],
labelLine: {
normal: {
show: false,
},
},
label: {
normal: {
position: "center",
},
},
data: [
{
value: value,
itemStyle: {
normal: {
color: "#68a8f2",
},
},
normal: {
show: false,
},
},
{
value: 100-value,
itemStyle: placeHolderStyle,
},
],
},
],
};
chChart.setOption(this.option);
window.onresize = chChart.resize;
})
},
},
watch:{
value: function (n,o) {
this.init()
}
}
})