|
After Width: | Height: | Size: 695 B |
|
Before Width: | Height: | Size: 432 KiB After Width: | Height: | Size: 425 KiB |
|
After Width: | Height: | Size: 432 KiB |
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 130 KiB |
|
After Width: | Height: | Size: 91 KiB |
@ -0,0 +1,380 @@ |
|||||||
|
<template> |
||||||
|
<div ref="dom" class="my-charts"></div> |
||||||
|
</template> |
||||||
|
|
||||||
|
<script> |
||||||
|
import * as echarts from "echarts"; |
||||||
|
import { on, off } from "@/libs/tools"; |
||||||
|
import { nextTick } from "vue"; |
||||||
|
let timerId = null; |
||||||
|
export default { |
||||||
|
name: "pie", |
||||||
|
props: { |
||||||
|
value: Object, |
||||||
|
totalNum:Number |
||||||
|
}, |
||||||
|
mounted() { |
||||||
|
this.total = this.value.data.reduce((totalNum, item) => totalNum + item.value, 0) |
||||||
|
this.initData(); |
||||||
|
}, |
||||||
|
data() { |
||||||
|
return { |
||||||
|
dom: null, |
||||||
|
option: null, |
||||||
|
timerId: null, |
||||||
|
total:0, |
||||||
|
timerOut:null, |
||||||
|
}; |
||||||
|
}, |
||||||
|
|
||||||
|
watch: { |
||||||
|
totalNum:{ |
||||||
|
handler(newVal, oldVal) { |
||||||
|
// this.total = newVal |
||||||
|
this.initData(); |
||||||
|
}, |
||||||
|
}, |
||||||
|
}, |
||||||
|
methods: { |
||||||
|
resize() { |
||||||
|
// this.dom.resize() |
||||||
|
}, |
||||||
|
initData() { |
||||||
|
const self = this; |
||||||
|
self.timerId = null |
||||||
|
if(self.timerOut){ |
||||||
|
clearTimeout(self.timerOut) |
||||||
|
} |
||||||
|
nextTick(() => { |
||||||
|
let angle = 0; //角度,用来做简单的动画效果的 |
||||||
|
|
||||||
|
let dom = echarts.init(this.$refs.dom); |
||||||
|
|
||||||
|
let title = this.value.title; |
||||||
|
|
||||||
|
let arr1 = []; |
||||||
|
let arr2 = []; |
||||||
|
let colorArr = this.value.data.map((val) => { |
||||||
|
return val.color; |
||||||
|
}); |
||||||
|
let xAxisData = this.value.data.map((val) => { |
||||||
|
return val.name; |
||||||
|
}); |
||||||
|
|
||||||
|
// console.log(this.value.data) |
||||||
|
// console.log(colorArr) |
||||||
|
|
||||||
|
let option = { |
||||||
|
title: { |
||||||
|
text: self.total, |
||||||
|
subtext: "纠纷总数", |
||||||
|
top: '35%', |
||||||
|
left: '24%', |
||||||
|
textStyle: { |
||||||
|
color: '#fff', |
||||||
|
fontSize: 20, |
||||||
|
fontWeight: 400 |
||||||
|
}, |
||||||
|
subtextStyle: { |
||||||
|
color: '#fff', |
||||||
|
fontSize: 14, |
||||||
|
fontWeight: 400 |
||||||
|
}, |
||||||
|
textAlign: 'center' |
||||||
|
}, |
||||||
|
legend: { |
||||||
|
show: true, |
||||||
|
icon: "circle", |
||||||
|
orient: "vertical", |
||||||
|
right: "0", |
||||||
|
top: "20%", |
||||||
|
itemWidth: 11, |
||||||
|
itemHeight: 11, |
||||||
|
width:220, |
||||||
|
itemGap: 30, |
||||||
|
formatter: ["{a|{name}}"].join("\n"), |
||||||
|
textStyle: { |
||||||
|
rich: { |
||||||
|
a: { |
||||||
|
width: 180, // 每个图例的宽度,具体根据字数调整 |
||||||
|
// lineHeight: 1, |
||||||
|
color: "#fff", |
||||||
|
}, |
||||||
|
}, |
||||||
|
}, |
||||||
|
}, |
||||||
|
color: colorArr, |
||||||
|
tooltip: { |
||||||
|
trigger: "item", |
||||||
|
}, |
||||||
|
grid: { |
||||||
|
left: "0", |
||||||
|
right: "0", |
||||||
|
top: "0", |
||||||
|
bottom: "0", |
||||||
|
// containLabel: true |
||||||
|
}, |
||||||
|
series: [ |
||||||
|
// 紫色 |
||||||
|
{ |
||||||
|
type: "custom", |
||||||
|
coordinateSystem: "none", |
||||||
|
renderItem: function (params, api) { |
||||||
|
return { |
||||||
|
type: "arc", |
||||||
|
shape: { |
||||||
|
cx: api.getWidth() / 4, |
||||||
|
cy: api.getHeight() / 2, |
||||||
|
r: Math.min(api.getWidth(), api.getHeight()) / 2, |
||||||
|
startAngle: ((0 + angle) * Math.PI) / 180, |
||||||
|
endAngle: ((90 + angle) * Math.PI) / 180, |
||||||
|
}, |
||||||
|
style: { |
||||||
|
stroke: "#8383FA", |
||||||
|
fill: "transparent", |
||||||
|
lineWidth: 1.5, |
||||||
|
}, |
||||||
|
silent: true, |
||||||
|
}; |
||||||
|
}, |
||||||
|
data: [0], |
||||||
|
}, |
||||||
|
{ |
||||||
|
// name: 'ring5', //紫点 |
||||||
|
type: "custom", |
||||||
|
coordinateSystem: "none", |
||||||
|
renderItem: function (params, api) { |
||||||
|
let x0 = api.getWidth() / 4; |
||||||
|
let y0 = api.getHeight() / 2; |
||||||
|
let r = Math.min(api.getWidth(), api.getHeight()) / 2; |
||||||
|
let point = getCirlPoint(x0, y0, r, 90 + angle); |
||||||
|
return { |
||||||
|
type: "circle", |
||||||
|
shape: { |
||||||
|
cx: point.x, |
||||||
|
cy: point.y, |
||||||
|
r: 4, |
||||||
|
}, |
||||||
|
style: { |
||||||
|
stroke: "#8450F9", //绿 |
||||||
|
fill: "#8450F9", |
||||||
|
}, |
||||||
|
silent: true, |
||||||
|
}; |
||||||
|
}, |
||||||
|
data: [0], |
||||||
|
}, |
||||||
|
// 蓝色 |
||||||
|
{ |
||||||
|
// name: 'ring5', |
||||||
|
type: "custom", |
||||||
|
coordinateSystem: "none", |
||||||
|
renderItem: function (params, api) { |
||||||
|
return { |
||||||
|
type: "arc", |
||||||
|
shape: { |
||||||
|
cx: api.getWidth() / 4, |
||||||
|
cy: api.getHeight() / 2, |
||||||
|
r: Math.min(api.getWidth(), api.getHeight()) / 2, |
||||||
|
startAngle: ((180 + angle) * Math.PI) / 180, |
||||||
|
endAngle: ((270 + angle) * Math.PI) / 180, |
||||||
|
}, |
||||||
|
style: { |
||||||
|
stroke: "#4386FA", |
||||||
|
fill: "transparent", |
||||||
|
lineWidth: 1.5, |
||||||
|
}, |
||||||
|
silent: true, |
||||||
|
}; |
||||||
|
}, |
||||||
|
data: [0], |
||||||
|
}, |
||||||
|
{ |
||||||
|
// name: 'ring5', // 蓝色 |
||||||
|
type: "custom", |
||||||
|
coordinateSystem: "none", |
||||||
|
renderItem: function (params, api) { |
||||||
|
let x0 = api.getWidth() / 4; |
||||||
|
let y0 = api.getHeight() / 2; |
||||||
|
let r = Math.min(api.getWidth(), api.getHeight()) / 2; |
||||||
|
let point = getCirlPoint(x0, y0, r, 180 + angle); |
||||||
|
return { |
||||||
|
type: "circle", |
||||||
|
shape: { |
||||||
|
cx: point.x, |
||||||
|
cy: point.y, |
||||||
|
r: 4, |
||||||
|
}, |
||||||
|
style: { |
||||||
|
stroke: "#4386FA", //绿 |
||||||
|
fill: "#4386FA", |
||||||
|
}, |
||||||
|
silent: true, |
||||||
|
}; |
||||||
|
}, |
||||||
|
data: [0], |
||||||
|
}, |
||||||
|
{ |
||||||
|
// name: 'ring5', |
||||||
|
type: "custom", |
||||||
|
coordinateSystem: "none", |
||||||
|
renderItem: function (params, api) { |
||||||
|
return { |
||||||
|
type: "arc", |
||||||
|
shape: { |
||||||
|
cx: api.getWidth() / 4, |
||||||
|
cy: api.getHeight() / 2, |
||||||
|
r: Math.min(api.getWidth(), api.getHeight()) / 2, |
||||||
|
startAngle: ((270 + -angle) * Math.PI) / 180, |
||||||
|
endAngle: ((40 + -angle) * Math.PI) / 180, |
||||||
|
}, |
||||||
|
style: { |
||||||
|
stroke: "#0CD3DB", |
||||||
|
fill: "transparent", |
||||||
|
lineWidth: 1.5, |
||||||
|
}, |
||||||
|
silent: true, |
||||||
|
}; |
||||||
|
}, |
||||||
|
data: [0], |
||||||
|
}, |
||||||
|
// 橘色 |
||||||
|
{ |
||||||
|
// name: 'ring5', |
||||||
|
type: "custom", |
||||||
|
coordinateSystem: "none", |
||||||
|
renderItem: function (params, api) { |
||||||
|
return { |
||||||
|
type: "arc", |
||||||
|
shape: { |
||||||
|
cx: api.getWidth() / 4, |
||||||
|
cy: api.getHeight() / 2, |
||||||
|
r: Math.min(api.getWidth(), api.getHeight()) / 2, |
||||||
|
startAngle: ((90 + -angle) * Math.PI) / 180, |
||||||
|
endAngle: ((220 + -angle) * Math.PI) / 180, |
||||||
|
}, |
||||||
|
style: { |
||||||
|
stroke: "#FF8E89", |
||||||
|
fill: "transparent", |
||||||
|
lineWidth: 1.5, |
||||||
|
}, |
||||||
|
silent: true, |
||||||
|
}; |
||||||
|
}, |
||||||
|
data: [0], |
||||||
|
}, |
||||||
|
{ |
||||||
|
// name: 'ring5', |
||||||
|
type: "custom", |
||||||
|
coordinateSystem: "none", |
||||||
|
renderItem: function (params, api) { |
||||||
|
let x0 = api.getWidth() / 4; |
||||||
|
let y0 = api.getHeight() / 2; |
||||||
|
let r = Math.min(api.getWidth(), api.getHeight()) / 2; |
||||||
|
let point = getCirlPoint(x0, y0, r, 90 + -angle); |
||||||
|
return { |
||||||
|
type: "circle", |
||||||
|
shape: { |
||||||
|
cx: point.x, |
||||||
|
cy: point.y, |
||||||
|
r: 4, |
||||||
|
}, |
||||||
|
style: { |
||||||
|
stroke: "#FF8E89", //粉 |
||||||
|
fill: "#FF8E89", |
||||||
|
}, |
||||||
|
silent: true, |
||||||
|
}; |
||||||
|
}, |
||||||
|
data: [0], |
||||||
|
}, |
||||||
|
{ |
||||||
|
// name: 'ring5', //绿点 |
||||||
|
type: "custom", |
||||||
|
coordinateSystem: "none", |
||||||
|
renderItem: function (params, api) { |
||||||
|
let x0 = api.getWidth() / 4; |
||||||
|
let y0 = api.getHeight() / 2; |
||||||
|
let r = Math.min(api.getWidth(), api.getHeight()) / 2; |
||||||
|
let point = getCirlPoint(x0, y0, r, 270 + -angle); |
||||||
|
return { |
||||||
|
type: "circle", |
||||||
|
shape: { |
||||||
|
cx: point.x, |
||||||
|
cy: point.y, |
||||||
|
r: 4, |
||||||
|
}, |
||||||
|
style: { |
||||||
|
stroke: "#0CD3DB", //绿 |
||||||
|
fill: "#0CD3DB", |
||||||
|
}, |
||||||
|
silent: true, |
||||||
|
}; |
||||||
|
}, |
||||||
|
data: [0], |
||||||
|
}, |
||||||
|
{ |
||||||
|
name: title, |
||||||
|
type: "pie", |
||||||
|
radius: ["72%", "60%"], |
||||||
|
// radius: "75%", |
||||||
|
center: ["25%", "50%"], |
||||||
|
hoverAnimation: false, |
||||||
|
label: { |
||||||
|
show: false, |
||||||
|
normal: { |
||||||
|
show: false, |
||||||
|
position: "center", |
||||||
|
}, |
||||||
|
}, |
||||||
|
itemStyle: { |
||||||
|
normal: { |
||||||
|
color: function (obj) { |
||||||
|
return obj.data.color; |
||||||
|
}, |
||||||
|
}, |
||||||
|
}, |
||||||
|
data: this.value.data, |
||||||
|
}, |
||||||
|
], |
||||||
|
}; |
||||||
|
this.option = option; |
||||||
|
//获取圆上面某点的坐标(x0,y0表示坐标,r半径,angle角度) |
||||||
|
function getCirlPoint(x0, y0, r, angle1) { |
||||||
|
let x1 = x0 + r * Math.cos((angle1 * Math.PI) / 180); |
||||||
|
let y1 = y0 + r * Math.sin((angle1 * Math.PI) / 180); |
||||||
|
return { |
||||||
|
x: x1, |
||||||
|
y: y1, |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
function draw() { |
||||||
|
angle = angle + 1; |
||||||
|
dom.setOption(option); |
||||||
|
self.timerId = window.requestAnimationFrame(draw); |
||||||
|
} |
||||||
|
if (this.timerId) { |
||||||
|
// dom.clear() |
||||||
|
// dom.dispose() |
||||||
|
cancelAnimationFrame(this.timerId); |
||||||
|
// dom.setOption(option, true); |
||||||
|
// myChart:图形绘制容器 |
||||||
|
// dom.removeAttribute('_echarts_instance_') |
||||||
|
} else { |
||||||
|
// setTimeout(() =>{ |
||||||
|
dom.setOption(option, true); |
||||||
|
// },500) |
||||||
|
} |
||||||
|
self.timerOut = setTimeout(() => { |
||||||
|
draw(); |
||||||
|
}, 2000); |
||||||
|
}); |
||||||
|
}, |
||||||
|
}, |
||||||
|
beforeUnmount() { |
||||||
|
cancelAnimationFrame(this.timerId); |
||||||
|
off(window, "resize", this.resize); |
||||||
|
}, |
||||||
|
}; |
||||||
|
</script> |
||||||