2026-05-15 09:36:17 +00:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="log-trend-chart">
|
|
|
|
|
|
<div class="chart-legend">
|
2026-05-27 09:17:57 +08:00
|
|
|
|
<span><i :style="{ background: chartColors.primary }"></i>日志总量</span>
|
|
|
|
|
|
<span><i :style="{ background: chartColors.danger }"></i>失败数</span>
|
2026-05-15 09:36:17 +00:00
|
|
|
|
</div>
|
2026-05-29 14:11:06 +08:00
|
|
|
|
<div ref="chartElement" class="chart-body" role="img" :aria-label="ariaLabel"></div>
|
2026-05-15 09:36:17 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-05-29 14:11:06 +08:00
|
|
|
|
import { computed, shallowRef } from 'vue'
|
|
|
|
|
|
import { BarChart as EChartsBarChart, LineChart as EChartsLineChart } from 'echarts/charts'
|
|
|
|
|
|
import { GridComponent, TooltipComponent } from 'echarts/components'
|
|
|
|
|
|
import { use } from 'echarts/core'
|
|
|
|
|
|
import { CanvasRenderer } from 'echarts/renderers'
|
|
|
|
|
|
|
|
|
|
|
|
import { useEcharts } from '../../composables/useEcharts.js'
|
2026-05-27 09:17:57 +08:00
|
|
|
|
import { useThemeColors } from '../../composables/useThemeColors.js'
|
2026-05-15 09:36:17 +00:00
|
|
|
|
|
2026-05-29 14:11:06 +08:00
|
|
|
|
use([GridComponent, TooltipComponent, EChartsBarChart, EChartsLineChart, CanvasRenderer])
|
2026-05-15 09:36:17 +00:00
|
|
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
|
labels: { type: Array, required: true },
|
|
|
|
|
|
totals: { type: Array, required: true },
|
|
|
|
|
|
failures: { type: Array, required: true }
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-05-29 14:11:06 +08:00
|
|
|
|
const chartElement = shallowRef(null)
|
2026-05-27 09:17:57 +08:00
|
|
|
|
const themeColors = useThemeColors()
|
|
|
|
|
|
const chartColors = computed(() => ({
|
|
|
|
|
|
primary: themeColors.value.chartPrimary,
|
|
|
|
|
|
danger: themeColors.value.chartDanger
|
|
|
|
|
|
}))
|
2026-05-15 09:36:17 +00:00
|
|
|
|
|
|
|
|
|
|
const maxTotal = computed(() => Math.max(...props.totals.map((value) => Number(value || 0)), 1))
|
2026-05-29 14:11:06 +08:00
|
|
|
|
const ariaLabel = computed(() =>
|
|
|
|
|
|
props.labels.map((label, index) => (
|
|
|
|
|
|
`${label}日志总量${props.totals[index] || 0},失败数${props.failures[index] || 0}`
|
|
|
|
|
|
)).join(';')
|
|
|
|
|
|
)
|
2026-05-15 09:36:17 +00:00
|
|
|
|
|
|
|
|
|
|
const chartOptions = computed(() => ({
|
2026-05-29 14:11:06 +08:00
|
|
|
|
backgroundColor: 'transparent',
|
2026-05-15 09:36:17 +00:00
|
|
|
|
animation: {
|
|
|
|
|
|
duration: 900,
|
|
|
|
|
|
easing: 'easeOutQuart'
|
|
|
|
|
|
},
|
2026-05-29 14:11:06 +08:00
|
|
|
|
grid: {
|
|
|
|
|
|
top: 12,
|
|
|
|
|
|
right: 18,
|
|
|
|
|
|
bottom: 20,
|
|
|
|
|
|
left: 34,
|
|
|
|
|
|
containLabel: true
|
|
|
|
|
|
},
|
|
|
|
|
|
tooltip: {
|
|
|
|
|
|
trigger: 'axis',
|
|
|
|
|
|
confine: true,
|
|
|
|
|
|
appendToBody: true,
|
|
|
|
|
|
backgroundColor: 'rgba(255,255,255,0.96)',
|
|
|
|
|
|
borderColor: '#e2e8f0',
|
|
|
|
|
|
borderWidth: 1,
|
|
|
|
|
|
padding: [9, 10],
|
|
|
|
|
|
textStyle: {
|
|
|
|
|
|
color: '#64748b',
|
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
|
fontWeight: 700
|
|
|
|
|
|
},
|
|
|
|
|
|
extraCssText: 'border-radius:4px;box-shadow:0 12px 28px rgba(15,23,42,.12);'
|
2026-05-15 09:36:17 +00:00
|
|
|
|
},
|
2026-05-29 14:11:06 +08:00
|
|
|
|
xAxis: {
|
|
|
|
|
|
type: 'category',
|
|
|
|
|
|
data: props.labels,
|
|
|
|
|
|
axisTick: { show: false },
|
|
|
|
|
|
axisLine: { lineStyle: { color: 'rgba(148, 163, 184, 0.28)' } },
|
|
|
|
|
|
axisLabel: {
|
|
|
|
|
|
color: '#64748b',
|
|
|
|
|
|
fontSize: 11,
|
|
|
|
|
|
fontWeight: 700
|
2026-05-15 09:36:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2026-05-29 14:11:06 +08:00
|
|
|
|
yAxis: {
|
|
|
|
|
|
type: 'value',
|
|
|
|
|
|
min: 0,
|
|
|
|
|
|
max: Math.max(maxTotal.value, 4),
|
|
|
|
|
|
axisLine: { show: false },
|
|
|
|
|
|
axisTick: { show: false },
|
|
|
|
|
|
axisLabel: {
|
|
|
|
|
|
color: '#64748b',
|
|
|
|
|
|
fontSize: 11,
|
|
|
|
|
|
fontWeight: 700
|
|
|
|
|
|
},
|
|
|
|
|
|
splitLine: { lineStyle: { color: '#f1f5f9' } }
|
|
|
|
|
|
},
|
|
|
|
|
|
series: [
|
|
|
|
|
|
{
|
|
|
|
|
|
name: '日志总量',
|
|
|
|
|
|
type: 'bar',
|
|
|
|
|
|
data: props.totals,
|
|
|
|
|
|
barWidth: 16,
|
|
|
|
|
|
itemStyle: {
|
|
|
|
|
|
color: chartColors.value.primary,
|
|
|
|
|
|
borderRadius: [4, 4, 0, 0]
|
2026-05-15 09:36:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2026-05-29 14:11:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
name: '失败数',
|
|
|
|
|
|
type: 'line',
|
|
|
|
|
|
data: props.failures,
|
|
|
|
|
|
smooth: true,
|
|
|
|
|
|
symbol: 'circle',
|
|
|
|
|
|
symbolSize: 7,
|
|
|
|
|
|
lineStyle: {
|
|
|
|
|
|
width: 2,
|
|
|
|
|
|
color: chartColors.value.danger
|
|
|
|
|
|
},
|
|
|
|
|
|
itemStyle: {
|
|
|
|
|
|
color: '#ffffff',
|
|
|
|
|
|
borderColor: chartColors.value.danger,
|
|
|
|
|
|
borderWidth: 2
|
2026-05-15 09:36:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-05-29 14:11:06 +08:00
|
|
|
|
]
|
2026-05-15 09:36:17 +00:00
|
|
|
|
}))
|
2026-05-29 14:11:06 +08:00
|
|
|
|
|
|
|
|
|
|
useEcharts(chartElement, chartOptions)
|
2026-05-15 09:36:17 +00:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.log-trend-chart {
|
|
|
|
|
|
height: 208px;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.chart-legend {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 16px;
|
|
|
|
|
|
margin-bottom: 12px;
|
|
|
|
|
|
color: #475569;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.chart-legend i {
|
|
|
|
|
|
display: inline-block;
|
|
|
|
|
|
width: 8px;
|
|
|
|
|
|
height: 8px;
|
|
|
|
|
|
margin-right: 4px;
|
|
|
|
|
|
border-radius: 2px;
|
|
|
|
|
|
vertical-align: middle;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.chart-body {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
min-height: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|