Browse Source

饼图需求

master
xuhuajiao 1 day ago
parent
commit
33b5fcd52b
  1. 13
      src/views/environmentalScreen/index.vue
  2. 88
      src/views/environmentalScreen/module/catePie.vue

13
src/views/environmentalScreen/index.vue

@ -574,11 +574,11 @@ export default {
},
formatAlarmChartData() {
const allZero = this.alarmStatisticsRaw.every(item => item.num === 0)
if (allZero) {
this.alarmChartData = [{ name: '无告警', value: 1, itemStyle: { color: '#666666' }}]
return
}
// const allZero = this.alarmStatisticsRaw.every(item => item.num === 0)
// if (allZero) {
// this.alarmChartData = [{ name: '', value: 1, itemStyle: { color: '#666666' }}]
// return
// }
const alarmColorMap = {
'门禁告警': '#F65164',
'消防告警': '#FFB800',
@ -589,7 +589,7 @@ export default {
const colorList = ['#F65164', '#339CFF', '#FFB800', '#1CADAB', '#9B6BCC', '#FF7D00']
this.alarmChartData = this.alarmStatisticsRaw.map((item, index) => {
const alarmName = item.alarmValue || '未知告警'
const alarmName = item.alarmValue
// 使使
const color = alarmColorMap[alarmName] || colorList[index % colorList.length] || '#666666'
@ -599,7 +599,6 @@ export default {
itemStyle: {
color: color
},
// 0
...(item.num === 0 ? { itemStyle: { color: color, opacity: 0.5 }} : {})
}
})

88
src/views/environmentalScreen/module/catePie.vue

@ -31,7 +31,7 @@ export default {
data() {
return {
chart: null,
timer: null //
timer: null
}
},
watch: {
@ -49,7 +49,7 @@ export default {
this.refreshEchart()
},
beforeDestroy() {
clearInterval(this.timer) //
clearInterval(this.timer)
if (this.chart) {
this.chart.dispose()
this.chart = null
@ -59,7 +59,7 @@ export default {
refreshEchart() {
if (this.refreshtime) {
this.timer = setInterval(() => {
this.drawChart() //
this.drawChart()
}, this.refreshtime)
} else {
this.initChart()
@ -77,30 +77,48 @@ export default {
if (!this.chart) this.initChart()
if (!this.chart) return
//
//
const chartData = this.cateData.length
? this.cateData
: [{ name: '无告警数据', value: 1, itemStyle: { color: '#666666' }}]
// ========== 0 ==========
const processedData = chartData.map(item => {
// 00.010
const displayValue = item.value === 0 ? 0.01 : item.value
// ========== 10 ==========
const isAllZero = chartData.every(item => item.value === 0)
// 0
// 000.010
const processedData = chartData.map((item, index, arr) => {
let displayValue
if (isAllZero) {
// 01/
displayValue = 1 / arr.length
} else {
// 000
displayValue = item.value === 0 ? 0.01 : item.value
}
return {
...item,
value: displayValue,
// tooltip/label
rawValue: item.value
rawValue: item.value // 0
}
})
// ========== 2tooltip0/0 ==========
const tooltipFormatter = (params) => {
const rawValue = params.data.rawValue
let percent = '0%'
// 00
if (!isAllZero && rawValue !== 0) {
percent = `${params.percent.toFixed(1)}%`
}
return `${params.name}: ${rawValue} 次 (${percent})`
}
const option = {
backgroundColor: 'transparent',
tooltip: {
trigger: 'item',
textStyle: { fontSize: 12 },
// 0
formatter: (params) => `${params.name}: ${params.data.rawValue} 次 (0%)`
formatter: tooltipFormatter
},
legend: {
bottom: 10,
@ -126,13 +144,17 @@ export default {
type: 'pie',
radius: ['30%', '60%'],
center: ['50%', '44%'],
avoidLabelOverlap: true, //
// 线0
avoidLabelOverlap: true,
// 0
labelLayout: {
hideOverlap: false, //
moveOverlap: 'shiftY' //
},
labelLine: {
show: true,
length: 10, //
length2: 15, //
smooth: 0.2, // 线
length: 10,
length2: 15,
smooth: 0.2,
lineStyle: (params) => ({
color: params.data.rawValue === 0
? 'rgba(255,255,255,0.3)'
@ -144,11 +166,11 @@ export default {
show: true,
fontSize: 11,
color: '#ffffff',
// 0
formatter: (params) => `${params.data.rawValue}`,
//
position: 'outer',
distance: 20 //
distance: 20,
// 0
...(isAllZero ? { rotate: 0 } : {})
},
emphasis: {
label: {
@ -165,10 +187,10 @@ export default {
data: processedData,
animationDuration: 1000,
animationEasing: 'cubicOut',
//
// 0
itemStyle: {
borderColor: 'transparent',
borderWidth: 1
borderColor: 'rgba(0,0,0,0.1)', //
borderWidth: 2 //
}
}
]
@ -186,27 +208,33 @@ export default {
</script>
<style lang="scss" scoped>
:deep(.ec-legend) {
::v-deep(.ec-legend) {
padding-bottom: 5px !important;
}
:deep(.ec-tooltip) {
::v-deep(.ec-tooltip) {
background: rgba(0, 20, 53, 0.9) !important;
border: 1px solid #339cff !important;
border-radius: 4px !important;
}
// 0
:deep(.ec-label) {
::v-deep(.ec-label) {
&[style*="0 次"] {
fill: rgba(255,255,255,0.5) !important;
}
}
//
:deep(.ec-pie) {
// 0
::v-deep(.ec-pie) {
g > path {
stroke: transparent !important;
stroke-width: 1px !important;
stroke: rgba(0,0,0,0.1) !important;
stroke-width: 2px !important;
stroke-linejoin: 'round' !important;
}
}
// 0
::v-deep(.ec-legend-text) {
opacity: 1 !important;
}
</style>
Loading…
Cancel
Save