chart3.vue 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <script setup>
  2. import { ref, onMounted } from 'vue'
  3. import * as echarts from 'echarts';
  4. const chart = ref();
  5. onMounted(() => { //加载图表
  6. chartInit()
  7. })
  8. function chartInit() {
  9. var myChart = echarts.init(chart.value);
  10. // 指定图表的配置项和数据
  11. var option = {
  12. grid: {
  13. left: '3%',
  14. right: '3%',
  15. top: '15%',
  16. bottom: '15%', // 增加底部空间
  17. containLabel: true
  18. },
  19. legend: {
  20. data: ['超警戒', '超保证'], // 明确图例项
  21. textStyle: {
  22. fontSize: 12, // 字体大小适配
  23. color: '#fff' // 字体颜色适配
  24. }
  25. },
  26. tooltip: {
  27. trigger: 'axis',
  28. axisPointer: { type: 'shadow' }
  29. },
  30. dataset: {
  31. source: [
  32. ['类型', '超警戒', '超保证'], // 列标题
  33. ['河道', 12, 4], // 示例数据
  34. ['大中型水库', 8, 2], // 示例数据
  35. ['闸坝', 5, 1], // 示例数据
  36. ['潮位', 9, 3] // 示例数据
  37. ]
  38. },
  39. xAxis: {
  40. type: 'category',
  41. data: ['河道', '大中型水库', '闸坝', '潮位'], // 指定横轴项
  42. axisLine: {
  43. lineStyle: {
  44. color: '#00ffe4', // 蓝色实线
  45. width: 2
  46. }
  47. },
  48. axisTick: {
  49. show: false // 隐藏刻度线
  50. }
  51. },
  52. yAxis: {
  53. type: 'value',
  54. name: '数量(个)', // 纵轴标题
  55. axisLine: {
  56. show: true,
  57. lineStyle: {
  58. color: '#00ffe4', // 蓝色实线
  59. width: 2
  60. }
  61. },
  62. splitLine: {
  63. show: false // 去除网格线
  64. }
  65. },
  66. series: [
  67. {
  68. name: '超警戒',
  69. type: 'bar',
  70. itemStyle: {
  71. color: '#0090ff' // 蓝色
  72. }
  73. },
  74. {
  75. name: '超保证',
  76. type: 'bar',
  77. itemStyle: {
  78. color: '#FF4500' // 红色
  79. }
  80. }
  81. ]
  82. }
  83. // 使用刚指定的配置项和数据显示图表。
  84. myChart.setOption(option);
  85. }
  86. </script>
  87. <template>
  88. <div class="box" style="flex:0 1 33.33%;">
  89. <div class="title">超警超保统计</div>
  90. <div class="boxstyle">
  91. <div ref="chart" style="width: 100%; height:120%;top: 30px;bottom: 0px;"></div>
  92. </div>
  93. </div>
  94. </template>
  95. <style scoped></style>