index.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <TechCard>
  3. <div class="card-title">历史告警统计</div>
  4. <div ref="chartRef" class="chart-container" />
  5. </TechCard>
  6. </template>
  7. <script setup lang="ts">
  8. import { onMounted, ref } from 'vue'
  9. import * as echarts from 'echarts'
  10. import { useChartResize } from '@/utils/useChartResize'
  11. import TechCard from '../TechCard/index.vue'
  12. // import { alarmHistoryData } from '@/store/data'
  13. defineOptions({
  14. name: 'AlarmHistoryCard',
  15. })
  16. const alarmHistoryData = ref({
  17. dates: ['2024-07-01', '2024-07-02', '2024-07-03', '2024-07-04', '2024-07-05'],
  18. values: [10, 15, 20, 12, 8],
  19. })
  20. const chartRef = ref<HTMLDivElement | null>(null)
  21. onMounted(() => {
  22. if (!chartRef.value) return
  23. const chart = echarts.init(chartRef.value)
  24. chart.setOption({
  25. grid: { top: 10, right: 20, bottom: 30, left: 30 },
  26. tooltip: {
  27. trigger: 'axis',
  28. axisPointer: { type: 'shadow' },
  29. },
  30. xAxis: {
  31. type: 'category',
  32. data: alarmHistoryData.value.dates,
  33. axisLine: { lineStyle: { color: '#2a3b5a' } },
  34. axisLabel: { color: '#9cc5e0', fontSize: 12 },
  35. },
  36. yAxis: {
  37. type: 'value',
  38. axisLine: { lineStyle: { color: '#2a3b5a' } },
  39. axisLabel: { color: '#9cc5e0', fontSize: 12 },
  40. splitLine: { lineStyle: { color: 'rgba(42, 59, 90, 0.3)' } },
  41. },
  42. series: [
  43. {
  44. name: '告警次数',
  45. type: 'line',
  46. smooth: true,
  47. symbol: 'circle',
  48. symbolSize: 8,
  49. data: alarmHistoryData.value.values,
  50. itemStyle: { color: '#f39c12' },
  51. lineStyle: {
  52. width: 3,
  53. color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
  54. { offset: 0, color: '#f39c12' },
  55. { offset: 1, color: '#e74c3c' },
  56. ]),
  57. },
  58. areaStyle: {
  59. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  60. { offset: 0, color: 'rgba(243, 156, 18, 0.3)' },
  61. { offset: 1, color: 'rgba(243, 156, 18, 0.1)' },
  62. ]),
  63. },
  64. },
  65. ],
  66. })
  67. useChartResize(chart, chartRef.value)
  68. })
  69. </script>
  70. <style scoped>
  71. .card-title {
  72. font-size: 16px;
  73. font-weight: bold;
  74. color: #f39c12;
  75. margin-bottom: 12px;
  76. text-align: center;
  77. }
  78. .chart-container {
  79. width: 100%;
  80. height: 100%;
  81. min-height: 280px;
  82. }
  83. </style>