inbreak.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <div class="person_box">
  3. <div ref="chartDistrict" style="width: 100%;height: 100%;"></div>
  4. </div>
  5. </template>
  6. <script setup>
  7. import * as echarts from 'echarts'
  8. defineProps({
  9. title: {
  10. type: String,
  11. default: '暂无数据'
  12. }
  13. })
  14. const chartDistrict = ref(null);
  15. let chartDom = null;
  16. const initAccess = () => {
  17. function xWrapText(params, num = 2) {
  18. let newParamsName = ''
  19. const paramsNameNumber = params.length
  20. const provideNumber = num //一行显示几个字
  21. const rowNumber = Math.ceil(paramsNameNumber / provideNumber)
  22. if (paramsNameNumber > provideNumber) {
  23. for (let p = 0; p < rowNumber; p++) {
  24. let tempStr = ''
  25. const start = p * provideNumber
  26. const end = start + provideNumber
  27. if (p == rowNumber - 1) {
  28. tempStr = params.substring(start, paramsNameNumber)
  29. } else {
  30. tempStr = params.substring(start, end) + ''
  31. }
  32. newParamsName += tempStr
  33. }
  34. } else {
  35. newParamsName = params
  36. }
  37. return newParamsName
  38. }
  39. let xData = ['12.20', '12.30', '12.40', '12.50', '13.00']
  40. let y1Data = [110, 90, 120, 70, 60]
  41. let y2Data = [15, 22, 13, 22, 13]
  42. chartDom = echarts.init(chartDistrict.value);
  43. let option = {
  44. grid: {
  45. left: '10%',
  46. right: '10%',
  47. top: '20%',
  48. bottom: '10%',
  49. },
  50. title: {
  51. show: false,
  52. },
  53. tooltip: {
  54. trigger: 'axis',
  55. backgroundColor: '#3A4667',
  56. borderColor: '#3A4667',
  57. textStyle: {
  58. color: '#fff'
  59. },
  60. axisPointer: {
  61. type: 'shadow', // 默认为直线,可选为:'line' | 'shadow'
  62. },
  63. },
  64. legend: {
  65. data: ['非法入侵', '非法入侵1'],
  66. right: 'center',
  67. top: '6%',
  68. itemWidth: 11,
  69. itemHeight: 11,
  70. textStyle: {
  71. color: '#B3CFFF',
  72. fontSize: 12,
  73. },
  74. },
  75. xAxis: [{
  76. type: 'category',
  77. boundaryGap: true,
  78. show: true,
  79. axisTick: {
  80. show: false,
  81. },
  82. axisLabel: {
  83. fontSize: 9.5,
  84. color: '#B3CFFF',
  85. formatter(params) {
  86. const res = xWrapText(params, 6) // 文字换行处理
  87. return params.length > 15 ? `${res.slice(0, 15)}...` : res
  88. },
  89. },
  90. axisLine: {
  91. lineStyle: {
  92. type: 'solid',
  93. color: '#4e608b', // 左边线的颜色
  94. width: '1', // 坐标线的宽度
  95. },
  96. },
  97. data: xData,
  98. },],
  99. yAxis: [{
  100. type: 'value',
  101. scale: true,
  102. name: '',
  103. axisLine: {
  104. show: false,
  105. },
  106. splitNumber: 2,
  107. axisTick: {
  108. show: false,
  109. },
  110. splitLine: {
  111. lineStyle: {
  112. color: '#4e608b', // 使用深浅的间隔色
  113. },
  114. },
  115. axisLabel: {
  116. fontSize: 12,
  117. color: '#B3CFFF',
  118. margin: 12,
  119. },
  120. min: 0,
  121. boundaryGap: [0.2, 0.2],
  122. },
  123. {
  124. type: 'value',
  125. scale: true,
  126. axisLine: {
  127. show: false,
  128. },
  129. splitNumber: 2,
  130. axisTick: {
  131. show: false,
  132. },
  133. axisLabel: {
  134. fontSize: 12,
  135. color: '#B3CFFF',
  136. margin: 12,
  137. formatter: '{value}亿',
  138. },
  139. splitLine: {
  140. lineStyle: {
  141. // 使用深浅的间隔色
  142. color: '#4e608b',
  143. },
  144. },
  145. name: '',
  146. min: 0,
  147. boundaryGap: [0.2, 0.2],
  148. },
  149. ],
  150. series: [{
  151. name: '非法入侵',
  152. yAxisIndex: 0,
  153. color: 'rgba(208, 222, 238, .5)',
  154. lineStyle: {
  155. color: 'rgba(208, 222, 238, .5)',
  156. },
  157. type: 'line',
  158. data: y1Data,
  159. },
  160. {
  161. name: '非法入侵1',
  162. type: 'bar',
  163. label: {
  164. normal: {
  165. show: false
  166. },
  167. },
  168. itemStyle: {
  169. normal: {
  170. color: new echarts.graphic.LinearGradient(
  171. 0,
  172. 1,
  173. 0,
  174. 0,
  175. [{
  176. offset: 0,
  177. color: 'rgba(123, 133, 255, 1)', // 0% 处的颜色
  178. },
  179. {
  180. offset: 1,
  181. color: 'rgba(96, 132, 255, 0)', // 100% 处的颜色
  182. },
  183. ],
  184. false
  185. ),
  186. },
  187. },
  188. barWidth: '20%',
  189. yAxisIndex: 1,
  190. data: y2Data,
  191. },
  192. ],
  193. };
  194. chartDom.setOption(option)
  195. };
  196. // 生命周期
  197. onMounted(() => {
  198. initAccess()
  199. });
  200. // 窗口自适应
  201. window.addEventListener('resize', () => {
  202. chartDom?.resize();
  203. });
  204. </script>
  205. <style scoped lang="scss">
  206. .person_box {
  207. width: 100%;
  208. height: 100%;
  209. display: flex;
  210. align-items: center;
  211. }
  212. </style>