chart-event.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <!-- **************************************NO.2 事件类型 分类*************************************** -->
  2. <template>
  3. <div class="chart-container">
  4. <div id="event" style="width: 50%; height:21vh;">
  5. </div>
  6. <div id="event2" style="width: 50%; height:21vh;">
  7. </div>
  8. </div>
  9. </template>
  10. <script>
  11. import {
  12. getEventSourceAndTypeStatistics
  13. } from '@/api/bigdata'
  14. import * as echarts from 'echarts'
  15. export default {
  16. name: 'event',
  17. data() {
  18. return {
  19. year: 2022,
  20. optionData: [],
  21. option2Data: []
  22. }
  23. },
  24. mounted() {
  25. this.getEventSourceAndTypeStatistics()
  26. },
  27. methods: {
  28. // 出处 https://echarts.apache.org/examples/zh/editor.html?c=pie-borderRadius
  29. //http://192.144.199.210:8080/editor/index.html?chart_id=K8nTnNyu0caN65uT
  30. getEventSourceAndTypeStatistics() {
  31. let that = this
  32. getEventSourceAndTypeStatistics({ day: that.year }).then(res => {
  33. this.optionData=res.data.source
  34. this.option2Data=res.data.type
  35. that.myEcharts()
  36. that.myEcharts2()
  37. })
  38. },
  39. myEcharts() {
  40. var chartDom = document.getElementById('event')
  41. var myChart = echarts.init(chartDom)
  42. var color = ['#02CDFF', '#62FBE7', '#7930FF', '#E148EB', '#ecb935']
  43. var option
  44. option = {
  45. color: color,
  46. tooltip: {
  47. trigger: 'item',
  48. position: 'top'
  49. },
  50. series: [
  51. {
  52. name: '事件类型',
  53. type: 'pie',
  54. center: ['50%', '60%'],
  55. radius: ['55%', '70%'],
  56. avoidLabelOverlap: false,
  57. label: {
  58. show: false,
  59. position: 'center'
  60. },
  61. emphasis: {
  62. label: {
  63. show: true,
  64. fontSize: '12',
  65. fontWeight: 'bold'
  66. }
  67. },
  68. labelLine: {
  69. show: false
  70. },
  71. data: this.optionData
  72. }
  73. ]
  74. }
  75. option && myChart.setOption(option)
  76. },
  77. myEcharts2() {
  78. var chartDom = document.getElementById('event2')
  79. var myChart = echarts.init(chartDom)
  80. let dashedPic =
  81. 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAM8AAAAOBAMAAAB6G1V9AAAAD1BMVEX////Kysrk5OTj4+TJycoJ0iFPAAAAG0lEQVQ4y2MYBaNgGAMTQQVFOiABhlEwCugOAMqzCykGOeENAAAAAElFTkSuQmCC'
  82. let color = ['#FF8700', '#ffc300', '#00e473', '#009DFF', '#0034ff', '#99ff00', '#E148EB', '#E148EB', '#E148EB', '#E148EB']
  83. var option
  84. let chartData = this.option2Data
  85. let arrName = []
  86. let arrValue = []
  87. let sum = 0
  88. let pieSeries = [],
  89. lineYAxis = []
  90. // 数据处理
  91. chartData.forEach((v, i) => {
  92. arrName.push(v.name)
  93. arrValue.push(v.value)
  94. sum = sum + v.value
  95. })
  96. // 图表option整理
  97. chartData.forEach((v, i) => {
  98. pieSeries.push({
  99. name: '沪昆线到达晚点情况',
  100. type: 'pie',
  101. clockWise: false,
  102. hoverAnimation: false,
  103. radius: [65 - i * 10 + '%', 66.5 - i * 10 + '%'],
  104. center: ['35%', '60%'],
  105. label: {
  106. show: false
  107. },
  108. itemStyle: {
  109. borderRadius: 20
  110. },
  111. data: [
  112. {
  113. value: v.value,
  114. name: v.name,
  115. itemStyle: {
  116. normal: {
  117. borderWidth: 5,
  118. borderColor: color[i]
  119. }
  120. }
  121. },
  122. {
  123. value: sum - v.value,
  124. name: '',
  125. itemStyle: {
  126. color: 'rgba(0,0,0,0)'
  127. }
  128. }
  129. ]
  130. })
  131. pieSeries.push({
  132. name: '',
  133. type: 'pie',
  134. silent: true,
  135. z: 1,
  136. clockWise: false, //顺时加载
  137. hoverAnimation: false, //鼠标移入变大
  138. radius: [65 - i * 10 + '%', 66.5 - i * 10 + '%'],
  139. center: ['35%', '60%'],
  140. label: {
  141. show: false
  142. },
  143. itemStyle: {
  144. borderCap: 'round',
  145. borderJoin: 'round'
  146. },
  147. data: [
  148. {
  149. value: 7.5,
  150. itemStyle: {
  151. color: '#E3F0FF'
  152. }
  153. },
  154. {
  155. value: 2.5,
  156. name: '',
  157. itemStyle: {
  158. color: 'rgba(0,0,0,0)'
  159. }
  160. }
  161. ]
  162. })
  163. v.percent = ((v.value / sum) * 100).toFixed(1) + '%'
  164. lineYAxis.push({
  165. value: i,
  166. textStyle: {
  167. rich: {
  168. circle: {
  169. color: color[i],
  170. padding: [0, 0]
  171. }
  172. }
  173. }
  174. })
  175. })
  176. option = {
  177. color: color,
  178. grid: {
  179. top: '20%',
  180. bottom: '45%',
  181. left: '40%',
  182. containLabel: false
  183. },
  184. yAxis: [
  185. {
  186. type: 'category',
  187. inverse: true,
  188. axisLine: {
  189. show: false
  190. },
  191. axisTick: {
  192. show: false
  193. },
  194. axisLabel: {
  195. formatter: function(params) {
  196. let item = chartData[params]
  197. console.log(item)
  198. return (
  199. '{circle|●}{name|' +
  200. item.name +
  201. '}{bd||}{percent|' +
  202. item.percent +
  203. '}'
  204. )
  205. },
  206. interval: 0,
  207. inside: true,
  208. textStyle: {
  209. color: '#333',
  210. fontSize: 10,
  211. rich: {
  212. line: {
  213. width: 170,
  214. height: 5,
  215. backgroundColor: { image: dashedPic }
  216. },
  217. name: {
  218. color: '#fff',
  219. fontSize: 10
  220. },
  221. bd: {
  222. color: '#72afff',
  223. padding: [0, 5],
  224. fontSize: 10
  225. },
  226. percent: {
  227. color: '#5cdad0',
  228. fontSize: 10
  229. },
  230. value: {
  231. color: '#333',
  232. fontSize: 16,
  233. fontWeight: 500,
  234. padding: [0, 0, 0, 10]
  235. },
  236. unit: {
  237. fontSize: 14
  238. }
  239. }
  240. },
  241. show: true
  242. },
  243. data: lineYAxis
  244. }
  245. ],
  246. xAxis: [
  247. {
  248. show: false
  249. }
  250. ],
  251. series: pieSeries
  252. }
  253. option && myChart.setOption(option)
  254. }
  255. }
  256. }
  257. </script>
  258. <style rel="stylesheet/scss" lang="scss" scoped>
  259. .chart-container {
  260. width: 100%;
  261. height: auto;
  262. position: relative;
  263. padding-bottom: 10px;
  264. display: flex;
  265. }
  266. </style>