chart-event.vue 6.9 KB

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