chart-event.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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(parseInt(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: parseInt(v.value),
  114. name: v.name,
  115. itemStyle: {
  116. normal: {
  117. borderWidth: 5,
  118. borderColor: color[i]
  119. }
  120. }
  121. },
  122. {
  123. value: parseInt(sum) - parseInt(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. if(parseInt(sum)==0||parseInt(v.value)==0){
  164. v.percent = 0+ '%'
  165. }else{
  166. v.percent = ((parseInt(v.value) / parseInt(sum)) * 100).toFixed(1) + '%';
  167. }
  168. lineYAxis.push({
  169. value: i,
  170. textStyle: {
  171. rich: {
  172. circle: {
  173. color: color[i],
  174. padding: [0, 0],
  175. },
  176. },
  177. },
  178. });
  179. });
  180. option = {
  181. color: color,
  182. grid: {
  183. top: '20%',
  184. bottom: '45%',
  185. left: '40%',
  186. containLabel: false,
  187. },
  188. yAxis: [
  189. {
  190. type: 'category',
  191. inverse: true,
  192. axisLine: {
  193. show: false,
  194. },
  195. axisTick: {
  196. show: false,
  197. },
  198. axisLabel: {
  199. formatter: function (params) {
  200. let item = chartData[params];
  201. console.log(item);
  202. return (
  203. '{circle|●}{name|' +
  204. item.name +
  205. '}{bd||}{percent|' +
  206. item.percent +
  207. '}'
  208. );
  209. },
  210. interval: 0,
  211. inside: true,
  212. textStyle: {
  213. color: '#333',
  214. fontSize: 10,
  215. rich: {
  216. line: {
  217. width: 170,
  218. height: 5,
  219. backgroundColor: {image: dashedPic},
  220. },
  221. name: {
  222. color: '#fff',
  223. fontSize: 10,
  224. },
  225. bd: {
  226. color: '#72afff',
  227. padding: [0, 5],
  228. fontSize: 10,
  229. },
  230. percent: {
  231. color: '#5cdad0',
  232. fontSize: 10,
  233. },
  234. value: {
  235. color: '#333',
  236. fontSize: 16,
  237. fontWeight: 500,
  238. padding: [0, 0, 0, 10],
  239. },
  240. unit: {
  241. fontSize: 14,
  242. },
  243. },
  244. },
  245. show: true,
  246. },
  247. data: lineYAxis,
  248. },
  249. ],
  250. xAxis: [
  251. {
  252. show: false,
  253. },
  254. ],
  255. series: pieSeries,
  256. };
  257. option && myChart.setOption(option);
  258. },
  259. },
  260. }
  261. </script>
  262. <style rel="stylesheet/scss" lang="scss" scoped>
  263. .chart-container {
  264. width: 100%;
  265. height: auto;
  266. position: relative;
  267. padding-bottom: 10px;
  268. display: flex;
  269. }
  270. </style>