chart-event.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 * as echarts from 'echarts';
  12. import {getSjlylxtj} from '@/api/bigdata'
  13. export default {
  14. name: 'event',
  15. data() {
  16. return {
  17. count: 0,
  18. data_sjlylxtj_source:[],
  19. data_sjlylxtj_type:[]
  20. }
  21. },
  22. mounted() {
  23. this.sjlylxtj()
  24. },
  25. methods: {
  26. sjlylxtj() {
  27. let that = this
  28. getSjlylxtj().then(resp => {
  29. that.data_sjlylxtj_source = resp.data.source
  30. that.data_sjlylxtj_type = resp.data.type
  31. that.myEcharts()
  32. that.myEcharts2()
  33. })
  34. },
  35. // 出处 https://echarts.apache.org/examples/zh/editor.html?c=pie-borderRadius
  36. //http://192.144.199.210:8080/editor/index.html?chart_id=K8nTnNyu0caN65uT
  37. myEcharts() {
  38. let that = this
  39. var chartDom = document.getElementById('event');
  40. var myChart = echarts.init(chartDom);
  41. var color = ['#02CDFF', '#62FBE7', '#7930FF', '#E148EB', '#ecb935']
  42. var option;
  43. option = {
  44. color: color,
  45. tooltip: {
  46. trigger: 'item',
  47. position: 'top'
  48. },
  49. series: [
  50. {
  51. name: '事件类型',
  52. type: 'pie',
  53. center: ['50%', '60%'],
  54. radius: ['55%', '70%'],
  55. avoidLabelOverlap: false,
  56. label: {
  57. show: false,
  58. position: 'center'
  59. },
  60. emphasis: {
  61. label: {
  62. show: true,
  63. fontSize: '12',
  64. fontWeight: 'bold'
  65. }
  66. },
  67. labelLine: {
  68. show: false
  69. },
  70. data: that.data_sjlylxtj_type
  71. },
  72. ]
  73. };
  74. option && myChart.setOption(option);
  75. },
  76. myEcharts2() {
  77. let that = this
  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', '#E148EB'];
  83. var option;
  84. let chartData = that.data_sjlylxtj_source
  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>