inspectionStatisticsEcharts.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <div class="inspectionStatisticsEcharts" id="inspectionStatisticsEcharts-box"></div>
  3. </template>
  4. <script>
  5. import { checkStatistics } from '@/apiDemo/safetyCheck/index'
  6. export default {
  7. name: 'inspectionStatisticsEcharts',
  8. data(){
  9. return{
  10. }
  11. },
  12. created(){
  13. },
  14. mounted(){
  15. this.eCharts();
  16. },
  17. methods:{
  18. //eCharts方法
  19. eCharts(){
  20. checkStatistics().then(response => {
  21. let data = {
  22. name : [],
  23. standards : [],
  24. notStandards : [],
  25. }
  26. for(let i=0;i<response.rows.length;i++){
  27. data.name.push(response.rows[i].yearMonth)
  28. if(response.rows[i].notStandards.indexOf('%') != -1){
  29. response.rows[i].notStandards = response.rows[i].notStandards.split('%')[0]
  30. data.notStandards.push(response.rows[i].notStandards)
  31. }else{
  32. data.notStandards.push(response.rows[i].notStandards)
  33. }
  34. if(response.rows[i].standards.indexOf('%') != -1){
  35. response.rows[i].standards = response.rows[i].standards.split('%')[0]
  36. data.standards.push(response.rows[i].standards)
  37. }else{
  38. data.standards.push(response.rows[i].standards)
  39. }
  40. }
  41. let myChart = this.$echarts.init(document.getElementById('inspectionStatisticsEcharts-box'));
  42. let option = {
  43. //你的代码
  44. tooltip: {
  45. show:true,
  46. trigger: 'axis',
  47. formatter: function(params) {
  48. let html = '<div>';
  49. html += '<p>'+params[0].name+'</p>'
  50. for(let i=0;i<params.length;i++){
  51. html += '<p>'+params[i].marker+'&nbsp'+params[i].seriesName+'&nbsp:&nbsp'+params[i].data+'%<p>'
  52. }
  53. return html;
  54. },
  55. axisPointer: {
  56. lineStyle: {
  57. color: 'rgb(126,199,255)',
  58. },
  59. },
  60. },
  61. legend: {
  62. show: true,
  63. icon: 'circle',
  64. itemWidth: 30,
  65. itemHeight: 10,
  66. right:20,
  67. textStyle: {
  68. color: 'rgba(0, 0, 0, 1)',
  69. fontSize: 14,
  70. padding: [0, 8, 0, 8]
  71. }
  72. },
  73. grid: {
  74. top: '20%',
  75. left: '10%',
  76. right: '7%',
  77. bottom: '15%',
  78. },
  79. xAxis: [
  80. {
  81. type: 'category',
  82. boundaryGap: false,
  83. axisLine: {
  84. show: true,
  85. lineStyle: {
  86. color: 'rgb(41,188,245)',
  87. },
  88. },
  89. axisLabel: {
  90. textStyle: {
  91. color: 'rgba(112, 151, 184, 1)',
  92. fontSize: 12,
  93. },
  94. },
  95. splitLine: {
  96. show: false,
  97. },
  98. axisTick: {
  99. show: false,
  100. },
  101. data: data.name,
  102. },
  103. ],
  104. yAxis: [
  105. {
  106. name: "",
  107. nameTextStyle: {
  108. color: "#fff",
  109. fontSize: 12,
  110. padding: [0, 60, 0, 0]
  111. },
  112. // minInterval: 1,
  113. type: 'value',
  114. splitLine: {
  115. show: false,
  116. },
  117. axisLine: {
  118. show: false,
  119. },
  120. axisLabel: {
  121. show: true,
  122. textStyle: {
  123. color: 'rgba(112, 151, 184, 1)',
  124. fontSize: 14
  125. }
  126. },
  127. axisTick: {
  128. show: false,
  129. },
  130. },
  131. ],
  132. series: [
  133. {
  134. name: '符合',
  135. type: 'line',
  136. symbol: 'circle',
  137. smooth: true,
  138. lineStyle: {
  139. normal: {
  140. width: 1,
  141. color: '#00AEFF', // 线条颜色
  142. },
  143. },
  144. showSymbol: false,
  145. itemStyle: {
  146. normal: {
  147. color: '#00AEFF',//拐点颜色
  148. label: {
  149. show: false, //开启显示
  150. color: '#fff',
  151. position: 'top', //在上方显示
  152. formatter: function (res) {
  153. console.log('res',res)
  154. if (res.value) {
  155. return res.value
  156. } else {
  157. return 0
  158. }
  159. },
  160. },
  161. },
  162. },
  163. areaStyle: {
  164. color: {
  165. type: 'linear',
  166. x: 0,
  167. y: 0,
  168. x2: 0,
  169. y2: 1,
  170. colorStops: [ // 渐变颜色
  171. {
  172. offset: 0,
  173. color: 'rgba(0,174,255,1)',
  174. },
  175. {
  176. offset: 0.5,
  177. color: 'rgba(0,174,255,0.38)',
  178. },
  179. {
  180. offset: 1,
  181. color: 'rgba(0,174,255,0)',
  182. },
  183. ],
  184. global: false,
  185. },
  186. },
  187. data: data.standards,
  188. },
  189. {
  190. name: '不符合',
  191. type: 'line',
  192. symbol: 'circle', // 默认是空心圆(中间是白色的),改成实心圆
  193. smooth: true,
  194. lineStyle: {
  195. normal: {
  196. width: 1,
  197. color: '#F66F00', // 线条颜色
  198. },
  199. },
  200. showSymbol: false,
  201. itemStyle: {
  202. normal: {
  203. color: '#F66F00',//拐点颜色
  204. label: {
  205. show: true, //开启显示
  206. color: '#fff',
  207. position: 'top', //在上方显示
  208. formatter: function (res) {
  209. if (res.value) {
  210. return res.value
  211. } else {
  212. return 0
  213. }
  214. },
  215. },
  216. },
  217. },
  218. areaStyle: {
  219. color: {
  220. type: 'linear',
  221. x: 0,
  222. y: 0,
  223. x2: 0,
  224. y2: 1,
  225. colorStops: [ // 渐变颜色
  226. {
  227. offset: 0,
  228. color: 'rgba(246,111,0,1)',
  229. },
  230. {
  231. offset: 0.5,
  232. color: 'rgba(246,111,0,0.38)',
  233. },
  234. {
  235. offset: 1,
  236. color: 'rgba(246,111,0,0)',
  237. },
  238. ],
  239. global: false,
  240. },
  241. },
  242. data: data.notStandards,
  243. }
  244. ]
  245. };
  246. myChart.setOption(option);
  247. })
  248. },
  249. }
  250. }
  251. </script>
  252. <style scoped>
  253. .inspectionStatisticsEcharts{
  254. height:236px;
  255. }
  256. </style>