2022-11-07 08:45:49 +08:00
|
|
|
<template>
|
2022-11-22 16:40:48 +08:00
|
|
|
<div
|
|
|
|
:id="id"
|
|
|
|
ref="fault-pie-chart"
|
|
|
|
class="right-content-quality-analysis"
|
|
|
|
style="position: absolute; top: 0; left: 0; width: 100%; height: 100%"
|
|
|
|
>
|
|
|
|
<!-- <div :id="id" ref="fault-pie-chart" class="fault-pie-chart" /> -->
|
2022-11-07 08:45:49 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import echarts from 'echarts'
|
|
|
|
import resize from '@/views/OperationalOverview/components/mixins/resize'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'RightContentFaultAnalysis',
|
|
|
|
mixins: [resize],
|
|
|
|
props: {
|
|
|
|
id: {
|
|
|
|
type: String,
|
2022-11-07 17:08:05 +08:00
|
|
|
default: 'default-fault-analysis-id'
|
2022-11-07 08:45:49 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
2022-11-07 17:08:05 +08:00
|
|
|
let totalRate = 0
|
|
|
|
const colors = [
|
|
|
|
{
|
|
|
|
type: 'linear',
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
x2: 1,
|
|
|
|
y2: 1,
|
|
|
|
colorStops: [
|
|
|
|
{ color: '#FFFFFF00', offset: 0 },
|
|
|
|
{ color: '#FB418C00', offset: 0.1 },
|
|
|
|
{ color: '#FB418C', offset: 1 } // 红
|
|
|
|
],
|
|
|
|
global: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'linear',
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
x2: 1,
|
|
|
|
y2: 1,
|
|
|
|
colorStops: [
|
|
|
|
{ color: '#FFFFFF00', offset: 0 },
|
|
|
|
{ color: '#DDB11200', offset: 0.1 },
|
|
|
|
{ color: '#DDB112', offset: 1 } // 黄
|
|
|
|
],
|
|
|
|
global: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'linear',
|
2022-11-17 10:26:16 +08:00
|
|
|
x: 0.5,
|
2022-11-07 17:08:05 +08:00
|
|
|
y: 1,
|
|
|
|
x2: 0,
|
|
|
|
y2: 0,
|
|
|
|
colorStops: [
|
|
|
|
{ color: '#FFFFFF00', offset: 0 },
|
|
|
|
{ color: '#1A99FF00', offset: 0.1 },
|
|
|
|
{ color: '#1A99FF', offset: 1 } // 兰
|
|
|
|
],
|
|
|
|
global: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'linear',
|
2022-11-17 10:26:16 +08:00
|
|
|
x: 0.5,
|
2022-11-07 17:08:05 +08:00
|
|
|
y: 1,
|
|
|
|
x2: 0,
|
|
|
|
y2: 0,
|
|
|
|
colorStops: [
|
|
|
|
{ color: '#FFFFFF00', offset: 0 },
|
|
|
|
{ color: '#A691FF00', offset: 0.1 },
|
|
|
|
{ color: '#A691FF', offset: 1 } // 紫 3
|
|
|
|
],
|
|
|
|
global: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'linear',
|
|
|
|
x: 0,
|
2022-11-17 10:26:16 +08:00
|
|
|
y: 0.5,
|
|
|
|
x2: 1,
|
|
|
|
y2: 0.5,
|
2022-11-07 17:08:05 +08:00
|
|
|
colorStops: [
|
|
|
|
{ color: '#FFFFFF00', offset: 0 },
|
|
|
|
{ color: '#49FBD600', offset: 0.1 },
|
|
|
|
{ color: '#49FBD6', offset: 1 } // 绿
|
|
|
|
],
|
|
|
|
global: false
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2022-11-11 15:52:50 +08:00
|
|
|
const demoData = [
|
2022-11-17 09:50:17 +08:00
|
|
|
{ value: 107, name: '破片' },
|
|
|
|
{ value: 146, name: '崩边' },
|
|
|
|
{ value: 43, name: '脏污' },
|
|
|
|
{ value: 83, name: '划擦伤' },
|
|
|
|
{ value: 20, name: '崩孔' }
|
2022-11-11 15:52:50 +08:00
|
|
|
]
|
|
|
|
|
2022-11-07 08:45:49 +08:00
|
|
|
return {
|
|
|
|
chart: null,
|
2022-11-07 17:08:05 +08:00
|
|
|
// default configs
|
|
|
|
configs: {
|
2022-11-07 08:45:49 +08:00
|
|
|
title: {
|
2022-11-07 17:08:05 +08:00
|
|
|
textAlign: 'center',
|
2022-11-23 17:00:25 +08:00
|
|
|
left: '67%',
|
|
|
|
top: '50%',
|
2022-11-17 10:26:16 +08:00
|
|
|
text: demoData.reduce((prev, curr) => prev + curr.value, 0),
|
2022-11-07 08:45:49 +08:00
|
|
|
textStyle: {
|
2022-11-07 17:08:05 +08:00
|
|
|
color: '#fff',
|
2022-11-11 15:52:50 +08:00
|
|
|
fontSize: 16,
|
2022-11-07 17:08:05 +08:00
|
|
|
fontWeight: 'normal'
|
2022-11-07 08:45:49 +08:00
|
|
|
},
|
2022-11-14 09:21:07 +08:00
|
|
|
itemGap: 2,
|
2022-11-07 17:08:05 +08:00
|
|
|
subtext: '总数',
|
2022-11-07 08:45:49 +08:00
|
|
|
subtextStyle: {
|
|
|
|
color: '#fff',
|
2022-11-11 15:52:50 +08:00
|
|
|
fontSize: 12,
|
2022-11-07 17:08:05 +08:00
|
|
|
fontWeight: 'lighter'
|
2022-11-07 08:45:49 +08:00
|
|
|
}
|
|
|
|
},
|
2022-11-22 16:40:48 +08:00
|
|
|
|
2022-11-07 17:08:05 +08:00
|
|
|
legend: {
|
2022-11-25 15:10:35 +08:00
|
|
|
selectedMode: false,
|
2022-11-14 09:21:07 +08:00
|
|
|
top: 0,
|
2022-11-11 15:52:50 +08:00
|
|
|
bottom: 0,
|
2022-11-22 16:40:48 +08:00
|
|
|
left: 0,
|
2022-11-07 17:08:05 +08:00
|
|
|
orient: 'vertical',
|
|
|
|
icon: 'none',
|
2022-11-17 10:26:16 +08:00
|
|
|
itemGap: 8,
|
2022-11-07 17:08:05 +08:00
|
|
|
itemWidth: 10,
|
|
|
|
formatter: function(name) {
|
|
|
|
// test data - dynamic
|
2022-11-11 15:52:50 +08:00
|
|
|
const testData = demoData
|
|
|
|
|
2022-11-07 17:08:05 +08:00
|
|
|
let pieLegendVale = {}
|
|
|
|
testData.filter((item, index) => {
|
|
|
|
if (item.name === name) {
|
|
|
|
pieLegendVale = item
|
|
|
|
}
|
|
|
|
})
|
|
|
|
const color = ['c', 'd', 'e', 'f', 'g']
|
|
|
|
const arr = [
|
|
|
|
'{' + color[testData.findIndex(item => item.name === name)] + '|}',
|
|
|
|
'{b|' + pieLegendVale.name + '}',
|
|
|
|
'{a|' + pieLegendVale.value + '}'
|
|
|
|
]
|
|
|
|
return arr.join(' ')
|
|
|
|
},
|
|
|
|
textStyle: {
|
|
|
|
rich: {
|
|
|
|
a: {
|
|
|
|
fontSize: 10,
|
|
|
|
color: 'rgba(255, 255, 255, 0.7)',
|
|
|
|
lineHeight: 16
|
|
|
|
},
|
|
|
|
b: {
|
|
|
|
// verticalAlign: 'top',
|
|
|
|
// align: 'center',
|
|
|
|
fontSize: 10,
|
|
|
|
color: 'rgba(255, 255, 255)'
|
|
|
|
},
|
|
|
|
c: {
|
|
|
|
// verticalAlign: 'top',
|
|
|
|
// align: 'center',
|
|
|
|
width: 10,
|
|
|
|
borderRadius: 5,
|
|
|
|
height: 10,
|
|
|
|
backgroundColor: '#FB418C'
|
|
|
|
},
|
|
|
|
d: {
|
|
|
|
// verticalAlign: 'top',
|
|
|
|
// align: 'center',
|
|
|
|
width: 10,
|
|
|
|
borderRadius: 5,
|
|
|
|
height: 10,
|
|
|
|
backgroundColor: '#DDB112'
|
|
|
|
},
|
|
|
|
e: {
|
|
|
|
// verticalAlign: 'top',
|
|
|
|
// align: 'center',
|
|
|
|
width: 10,
|
|
|
|
borderRadius: 5,
|
|
|
|
height: 10,
|
|
|
|
backgroundColor: '#1A99FF'
|
|
|
|
},
|
|
|
|
f: {
|
|
|
|
// verticalAlign: 'top',
|
|
|
|
// align: 'center',
|
|
|
|
width: 10,
|
|
|
|
borderRadius: 5,
|
|
|
|
height: 10,
|
|
|
|
backgroundColor: '#A691FF'
|
|
|
|
},
|
|
|
|
g: {
|
|
|
|
// verticalAlign: 'top',
|
|
|
|
// align: 'center',
|
|
|
|
width: 10,
|
|
|
|
borderRadius: 5,
|
|
|
|
height: 10,
|
|
|
|
backgroundColor: '#49FBD6'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-11-07 08:45:49 +08:00
|
|
|
series: [
|
|
|
|
{
|
2022-11-25 15:10:35 +08:00
|
|
|
silent: true,
|
2022-11-07 17:08:05 +08:00
|
|
|
name: 'PieForm',
|
2022-11-07 08:45:49 +08:00
|
|
|
type: 'pie',
|
2022-11-23 17:00:25 +08:00
|
|
|
center: ['68%', '61%'],
|
2022-11-22 16:40:48 +08:00
|
|
|
radius: ['42%', '60%'],
|
2022-11-07 17:08:05 +08:00
|
|
|
avoidLabelOverlap: true,
|
|
|
|
label: {
|
|
|
|
formatter: params => {
|
|
|
|
const colorMap = ['first', 'second', 'third', 'fourth', 'fifth']
|
|
|
|
return `{${colorMap[params.dataIndex]}|${params.percent} %}`
|
|
|
|
},
|
|
|
|
rich: {
|
|
|
|
first: { color: '#FB418C', fontSize: 8 },
|
|
|
|
second: { color: '#DDB112', fontSize: 8 },
|
|
|
|
third: { color: '#1A99FF', fontSize: 8 },
|
|
|
|
fourth: { color: '#A691FF', fontSize: 8 },
|
|
|
|
fifth: { color: '#49FBD6', fontSize: 8 }
|
2022-11-07 08:45:49 +08:00
|
|
|
}
|
|
|
|
},
|
2022-11-14 09:21:07 +08:00
|
|
|
labelLine: {
|
|
|
|
length: 5,
|
|
|
|
length2: 5
|
|
|
|
},
|
2022-11-07 17:08:05 +08:00
|
|
|
itemStyle: {
|
|
|
|
color: params => {
|
|
|
|
/** 计算渐变方向的过程,只靠 dataIndex 不太行 */
|
|
|
|
const { dataIndex, percent } = params
|
|
|
|
const colorGradient = colors[dataIndex]
|
|
|
|
if (totalRate + percent < 25) {
|
|
|
|
/** 也许这里需要完善,但目前工作良好 */
|
2022-11-28 09:45:49 +08:00
|
|
|
(() => {})()
|
2022-11-07 17:08:05 +08:00
|
|
|
} else if (totalRate + percent < 50) {
|
|
|
|
colorGradient.x = 0
|
|
|
|
colorGradient.y = 0
|
|
|
|
colorGradient.x2 = 1
|
|
|
|
colorGradient.y2 = 1
|
2022-11-14 09:21:07 +08:00
|
|
|
} else if (totalRate + percent >= 50 && dataIndex === 1) {
|
|
|
|
colorGradient.x = 1
|
|
|
|
colorGradient.y = 1
|
|
|
|
colorGradient.x2 = 0
|
|
|
|
colorGradient.y2 = 0
|
2022-11-07 17:08:05 +08:00
|
|
|
} else if (totalRate + percent < 100) {
|
|
|
|
/** 也许这里需要完善,但目前工作良好 */
|
2022-11-28 09:45:49 +08:00
|
|
|
(() => {})()
|
2022-11-07 17:08:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
totalRate += percent
|
|
|
|
return colorGradient
|
|
|
|
}
|
|
|
|
},
|
2022-11-11 15:52:50 +08:00
|
|
|
data: demoData
|
2022-11-07 08:45:49 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
2022-11-11 15:52:50 +08:00
|
|
|
window.addEventListener('resize', () => {
|
2022-11-07 17:08:05 +08:00
|
|
|
if (this.chart) {
|
|
|
|
this.chart.resize()
|
2022-11-11 15:52:50 +08:00
|
|
|
this.$nextTick(() => {
|
|
|
|
// 重新绘制文本大小
|
|
|
|
this.applyChartOption()
|
|
|
|
})
|
2022-11-07 17:08:05 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-11-07 08:45:49 +08:00
|
|
|
this.$nextTick(() => {
|
2022-11-07 17:08:05 +08:00
|
|
|
// if (!this.chart) this.chart = echarts.init(this.$refs.chartContainer, { width: '100%', height: '100%' })
|
2022-11-07 08:45:49 +08:00
|
|
|
if (!this.chart) this.chart = echarts.init(this.$refs['fault-pie-chart'])
|
2022-11-11 15:52:50 +08:00
|
|
|
this.applyChartOption()
|
2022-11-07 17:08:05 +08:00
|
|
|
this.chart.resize()
|
2022-11-07 08:45:49 +08:00
|
|
|
})
|
|
|
|
},
|
2022-11-07 17:08:05 +08:00
|
|
|
|
2022-11-11 15:52:50 +08:00
|
|
|
methods: {
|
|
|
|
calcFontsize(baseSize) {
|
|
|
|
const beilv = document.documentElement.style.getPropertyValue('--beilv')
|
|
|
|
return beilv * baseSize
|
|
|
|
},
|
|
|
|
applyChartOption() {
|
2022-11-28 09:45:49 +08:00
|
|
|
// const fs1 = this.calcFontsize(1 /** px*/)
|
|
|
|
// const fs3 = this.calcFontsize(3 /** px*/)
|
2022-11-14 09:21:07 +08:00
|
|
|
const fs5 = this.calcFontsize(5 /** px*/)
|
|
|
|
const fs8 = this.calcFontsize(8 /** px*/)
|
|
|
|
const fs10 = this.calcFontsize(10 /** px*/)
|
2022-11-22 16:40:48 +08:00
|
|
|
const fs12 = this.calcFontsize(12 /** px*/)
|
2022-11-14 09:21:07 +08:00
|
|
|
const fs16 = this.calcFontsize(16 /** px*/)
|
2022-11-22 16:40:48 +08:00
|
|
|
const titleSize = this.calcFontsize(22 /** px*/)
|
|
|
|
const subtitleSize = this.calcFontsize(14 /** px*/)
|
2022-11-11 15:52:50 +08:00
|
|
|
|
2022-11-22 16:40:48 +08:00
|
|
|
this.configs.title.textStyle.fontSize = titleSize
|
|
|
|
this.configs.title.subtextStyle.fontSize = subtitleSize
|
2022-11-11 15:52:50 +08:00
|
|
|
|
2022-11-23 14:03:56 +08:00
|
|
|
this.configs.legend.top = '26%'
|
|
|
|
this.configs.legend.left = fs8
|
2022-11-22 16:40:48 +08:00
|
|
|
this.configs.legend.itemGap = fs8
|
2022-11-14 09:21:07 +08:00
|
|
|
this.configs.legend.itemWidth = fs8
|
2022-11-11 15:52:50 +08:00
|
|
|
|
2022-11-22 16:40:48 +08:00
|
|
|
this.configs.legend.textStyle.rich.a.fontSize = fs12
|
2022-11-11 15:52:50 +08:00
|
|
|
this.configs.legend.textStyle.rich.a.lineHeight = fs16
|
2022-11-22 16:40:48 +08:00
|
|
|
this.configs.legend.textStyle.rich.b.fontSize = fs12
|
2022-11-11 15:52:50 +08:00
|
|
|
// this.configs.legend.textStyle.rich.b.lineHeight = fs16
|
2022-11-14 09:21:07 +08:00
|
|
|
this.configs.legend.textStyle.rich.c.width = fs8
|
|
|
|
this.configs.legend.textStyle.rich.c.height = fs8
|
2022-11-11 15:52:50 +08:00
|
|
|
this.configs.legend.textStyle.rich.c.borderRadius = fs5
|
2022-11-14 09:21:07 +08:00
|
|
|
this.configs.legend.textStyle.rich.d.width = fs8
|
|
|
|
this.configs.legend.textStyle.rich.d.height = fs8
|
2022-11-11 15:52:50 +08:00
|
|
|
this.configs.legend.textStyle.rich.d.borderRadius = fs5
|
2022-11-14 09:21:07 +08:00
|
|
|
this.configs.legend.textStyle.rich.e.width = fs8
|
|
|
|
this.configs.legend.textStyle.rich.e.height = fs8
|
2022-11-11 15:52:50 +08:00
|
|
|
this.configs.legend.textStyle.rich.e.borderRadius = fs5
|
2022-11-14 09:21:07 +08:00
|
|
|
this.configs.legend.textStyle.rich.f.width = fs8
|
|
|
|
this.configs.legend.textStyle.rich.f.height = fs8
|
2022-11-11 15:52:50 +08:00
|
|
|
this.configs.legend.textStyle.rich.f.borderRadius = fs5
|
2022-11-14 09:21:07 +08:00
|
|
|
this.configs.legend.textStyle.rich.g.width = fs8
|
|
|
|
this.configs.legend.textStyle.rich.g.height = fs8
|
2022-11-11 15:52:50 +08:00
|
|
|
this.configs.legend.textStyle.rich.g.borderRadius = fs5
|
|
|
|
|
2022-11-23 17:00:25 +08:00
|
|
|
this.configs.series[0].label.rich.first.fontSize = fs10
|
|
|
|
this.configs.series[0].label.rich.second.fontSize = fs10
|
|
|
|
this.configs.series[0].label.rich.third.fontSize = fs10
|
|
|
|
this.configs.series[0].label.rich.fourth.fontSize = fs10
|
|
|
|
this.configs.series[0].label.rich.fifth.fontSize = fs10
|
2022-11-11 15:52:50 +08:00
|
|
|
|
|
|
|
this.chart.setOption(this.configs)
|
|
|
|
}
|
|
|
|
}
|
2022-11-07 08:45:49 +08:00
|
|
|
}
|
|
|
|
</script>
|
2022-11-07 17:08:05 +08:00
|
|
|
|
2022-11-07 08:45:49 +08:00
|
|
|
<style scoped>
|
2022-11-22 16:40:48 +08:00
|
|
|
/* .right-content-quality-analysis {
|
2022-11-07 08:45:49 +08:00
|
|
|
height: calc(100% - 32px);
|
2022-11-22 16:40:48 +08:00
|
|
|
} */
|
2022-11-07 08:45:49 +08:00
|
|
|
|
|
|
|
.fault-pie-chart {
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fault-pie-chart >>> div {
|
|
|
|
width: 100% !important;
|
|
|
|
}
|
|
|
|
</style>
|