index.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. defineOptions({
  13. name: 'DeviceLocationCard',
  14. })
  15. const chartRef = ref<HTMLDivElement | null>(null)
  16. onMounted(() => {
  17. if (!chartRef.value) return
  18. const chart = echarts.init(chartRef.value)
  19. chart.setOption({
  20. tooltip: {
  21. trigger: 'axis',
  22. axisPointer: { type: 'shadow' },
  23. formatter: '{b}: {c} 台',
  24. },
  25. grid: {
  26. left: 60,
  27. right: 20,
  28. top: 20,
  29. bottom: 20,
  30. },
  31. xAxis: {
  32. type: 'value',
  33. axisLabel: { color: '#9cc5e0' },
  34. splitLine: { show: false },
  35. },
  36. yAxis: {
  37. type: 'category',
  38. data: ['卫生间', '卧室', '客厅', '餐厅'],
  39. axisLabel: { color: '#9cc5e0' },
  40. axisTick: { show: false },
  41. axisLine: { show: false },
  42. },
  43. series: [
  44. {
  45. type: 'bar',
  46. data: [12, 8, 6, 4],
  47. barWidth: 14,
  48. itemStyle: {
  49. color: (params: { dataIndex: number }) => {
  50. const colors = ['#4dc9e6', '#6de4ff', '#2572ed', '#1a57c9']
  51. return colors[params.dataIndex]
  52. },
  53. },
  54. label: {
  55. show: true,
  56. position: 'right',
  57. color: '#00f0ff',
  58. fontSize: 12,
  59. },
  60. },
  61. ],
  62. })
  63. useChartResize(chart, chartRef.value)
  64. })
  65. </script>
  66. <style scoped>
  67. .card-title {
  68. font-size: 16px;
  69. font-weight: bold;
  70. color: #00f0ff;
  71. margin-bottom: 12px;
  72. text-align: center;
  73. }
  74. .chart-container {
  75. width: 100%;
  76. height: 100%;
  77. min-height: 150px;
  78. }
  79. </style>