AlarmBarChartComponent.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <el-skeleton :loading="loading" animated>
  3. <template #default>
  4. <div style="height: 235px;">
  5. <v-chart class="h-full" :option="option" />
  6. </div>
  7. </template>
  8. </el-skeleton>
  9. </template>
  10. <script setup>
  11. import { ref, onMounted } from 'vue'
  12. import { use } from 'echarts/core'
  13. import VChart from 'vue-echarts'
  14. import {
  15. BarChart
  16. } from 'echarts/charts'
  17. import {
  18. TitleComponent,
  19. TooltipComponent,
  20. GridComponent,
  21. LegendComponent
  22. } from 'echarts/components'
  23. import {
  24. CanvasRenderer
  25. } from 'echarts/renderers'
  26. import { getAlarmEventWeeklyCount } from '@/api/hnyz/alarmEvent'
  27. use([
  28. CanvasRenderer,
  29. BarChart,
  30. TitleComponent,
  31. TooltipComponent,
  32. GridComponent,
  33. LegendComponent
  34. ])
  35. const loading = ref(true)
  36. const option = ref({})
  37. const { proxy } = getCurrentInstance()
  38. const { alarm_type } = proxy.useDict('alarm_type')
  39. onMounted(() => {
  40. getAlarmEventWeeklyCount().then(res => {
  41. if (res.code === 200) {
  42. const xAxisLabels = alarm_type.value.map(item => item.label)
  43. const valueMap = Object.fromEntries(res.data.map(item => [item.alarm_type, item.alarmCount]))
  44. const barData = alarm_type.value.map(item => valueMap[item.value] || 0)
  45. option.value = {
  46. title: { text: '近期告警统计', left: 'center' },
  47. tooltip: {},
  48. xAxis: {
  49. type: 'category',
  50. data: xAxisLabels
  51. },
  52. yAxis: { type: 'value' },
  53. series: [
  54. {
  55. name: '告警次数',
  56. type: 'bar',
  57. data: barData,
  58. itemStyle: {
  59. color: '#f56c6c'
  60. }
  61. }
  62. ]
  63. }
  64. loading.value = false
  65. }
  66. })
  67. })
  68. </script>
  69. <style scoped lang="scss">
  70. .stat-card {
  71. display: flex;
  72. align-items: center;
  73. }
  74. </style>