hiddenDangerStatisticsEcharts.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <div class="hiddenDangerStatisticsEcharts">
  3. <div class="title-button-box">
  4. <p :class="hdLevel==1?'check-p':''" @click="titleButtonClick(1)">一级指标</p>
  5. <p :class="hdLevel==2?'check-p':''" @click="titleButtonClick(2)">二级指标</p>
  6. <p :class="hdLevel==3?'check-p':''" @click="titleButtonClick(3)">三级指标</p>
  7. </div>
  8. <div class="hiddenDangerStatisticsEcharts-box" id="hiddenDangerStatisticsEcharts-box">
  9. </div>
  10. </div>
  11. </template>
  12. <script>
  13. import echarts from 'echarts'
  14. import { hiddenCountByType, collegCheckHiddenCountByType } from '@/api/safetyCheck/index.js'
  15. export default {
  16. name: 'hiddenDangerStatisticsEcharts',
  17. data(){
  18. return{
  19. hdLevel:1,
  20. }
  21. },
  22. created(){
  23. },
  24. mounted(){
  25. this.schoolEcharts();
  26. // this.departmentEcharts();
  27. },
  28. methods:{
  29. titleButtonClick(type){
  30. if(this.hdLevel != type){
  31. this.$set(this,'hdLevel',type);
  32. this.schoolEcharts();
  33. // this.departmentEcharts();
  34. }
  35. },
  36. schoolEcharts(){
  37. hiddenCountByType({hdLevel:this.hdLevel}).then(response => {
  38. let myChart = this.$echarts.init(document.getElementById('hiddenDangerStatisticsEcharts-box'));
  39. let data = [];
  40. for(let i=0;i<response.rows.length;i++){
  41. // substring
  42. console.log(response.rows[i].collegeName.length)
  43. let obj = {
  44. name:response.rows[i].collegeName.length>8?response.rows[i].collegeName.substring(0,8)+'..':response.rows[i].collegeName,
  45. nameText:response.rows[i].collegeName,
  46. value:response.rows[i].sumTotal,
  47. }
  48. data.push(obj);
  49. }
  50. let option = {
  51. legend: {
  52. show:false,
  53. },
  54. tooltip: {
  55. confine: true,
  56. trigger: 'item',
  57. // formatter: '{b} : {c}'
  58. formatter: params => {
  59. console.log('params',params)
  60. return `${params.data.nameText} 隐患:${params.data.value} 占比:${params.percent}%`
  61. },
  62. },
  63. series: [
  64. {
  65. avoidLabelOverlap: false,
  66. type: 'pie',
  67. left:20,
  68. right:20,
  69. roseType: 'area', // 玫瑰图
  70. center: ['50%', '50%'],
  71. radius: ['0%', '40%'],
  72. label: {
  73. normal: {
  74. formatter: '{b}\n隐患{c}\t占比{d}%',
  75. textStyle: {
  76. fontSize: 12
  77. },
  78. padding: [0, -110, 26, -110],
  79. }
  80. },
  81. labelLine: {
  82. normal: {
  83. length: 30,
  84. length2: 110,
  85. }
  86. },
  87. data: data,
  88. itemStyle: {
  89. normal: {
  90. color: function (colors) {
  91. var colorList = ['#009DFF', '#FFA200', '#FF2A00', '#A069FF', '#41BE26', '#2758E0', '#39dbed', '#ff5e86','#a52a2a','#4682b4','#9400d3'];
  92. return colorList[colors.dataIndex];
  93. }
  94. },
  95. }
  96. }
  97. ]
  98. };
  99. myChart.setOption(option);
  100. });
  101. },
  102. departmentEcharts(){
  103. collegCheckHiddenCountByType({hdLevel:this.hdLevel}).then(response => {
  104. let myChart = this.$echarts.init(document.getElementById('hiddenDangerStatisticsEcharts-box'));
  105. let data = {
  106. name:[],
  107. nameText:[],
  108. text:[],
  109. num: [],
  110. }
  111. for(let i=0;i<response.rows.length;i++){
  112. data.name.push(response.rows[i].subjectName.length>8?response.rows[i].subjectName.substring(0,8)+'..':response.rows[i].subjectName)
  113. data.nameText.push(response.rows[i].subjectName)
  114. data.text.push(response.rows[i].hazardCheckName)
  115. data.num.push(response.rows[i].sumTotal)
  116. }
  117. let option = {
  118. grid: {
  119. left: '30%',
  120. top: '8%',
  121. right: '15%',
  122. bottom: '15%',
  123. },
  124. tooltip: {
  125. trigger: 'axis',
  126. formatter: params => {
  127. console.log('params',params)
  128. console.log('dataIndex',params[0].dataIndex)
  129. return data.nameText[params[0].dataIndex] +' 隐患:'+ data.num[params[0].dataIndex]
  130. // return `${params.data.nameText} 隐患:${params.data.value} 占比:${params.percent}%`
  131. },
  132. backgroundColor: 'rgba(0, 0, 0, 0.6)', // 提示框背景色
  133. borderColor: '#05050F', // 提示框边框色
  134. textStyle: {
  135. color: '#fff', // 提示框文本颜色
  136. },
  137. axisPointer: {
  138. type: 'none',
  139. },
  140. },
  141. legend: {
  142. show:false,
  143. },
  144. xAxis: {
  145. type: 'value',
  146. position: "bottom",
  147. splitLine: {
  148. show: false,
  149. },
  150. axisTick: {
  151. show: false,
  152. },
  153. axisLabel: {
  154. textStyle: {
  155. color: '#333',
  156. fontSize: 12,
  157. },
  158. },
  159. axisLine: {
  160. show: true,
  161. lineStyle: {
  162. color: 'rgba(216,216,216,1)',
  163. },
  164. },
  165. },
  166. yAxis: {
  167. type: 'category',
  168. splitLine: {
  169. show: false,
  170. },
  171. axisTick: {
  172. show: false,
  173. },
  174. data: data.name,
  175. axisLabel: {
  176. textStyle: {
  177. color: '#333',
  178. fontSize: 12,
  179. },
  180. },
  181. axisLine: {
  182. lineStyle: {
  183. color: 'rgba(216,216,216,1)',
  184. },
  185. },
  186. },
  187. series: [
  188. {
  189. name: '隐患',
  190. type: 'bar',
  191. data: data.num,
  192. itemStyle: {
  193. emphasis: {
  194. barBorderRadius: [0, 20, 20, 0],
  195. },
  196. normal: {
  197. barBorderRadius: [0, 20, 20, 0],
  198. color: new echarts.graphic.LinearGradient(
  199. 0,
  200. 0,
  201. 1,
  202. 0,
  203. [
  204. {
  205. offset: 0,
  206. color: 'rgba(246,111,0,0.1)', // 0% 处的颜色
  207. },
  208. {
  209. offset: 1,
  210. color: 'rgba(246,111,0,1)', // 100% 处的颜色
  211. },
  212. ],
  213. false
  214. ),
  215. },
  216. },
  217. label: {
  218. normal: {
  219. show: true,
  220. formatter: params => {
  221. return '隐患'+params.data
  222. },
  223. position: 'insideRight',
  224. offset: [40, 1.5],
  225. textStyle: {
  226. color: '#333',
  227. fontSize: 12,
  228. },
  229. },
  230. },
  231. },
  232. ],
  233. barCategoryGap: '60%',
  234. };
  235. myChart.setOption(option);
  236. })
  237. },
  238. }
  239. }
  240. </script>
  241. <style scoped lang="scss">
  242. .hiddenDangerStatisticsEcharts{
  243. height:483px;
  244. .title-button-box{
  245. display: flex;
  246. border:1px solid #0183fa;
  247. width:300px;
  248. margin:32px 71px 0;
  249. p{
  250. width:100px;
  251. line-height:30px;
  252. text-align: center;
  253. color:#0183fa;
  254. cursor: pointer;
  255. }
  256. p:nth-child(2){
  257. border-left:1px solid #0183fa;
  258. border-right:1px solid #0183fa;
  259. }
  260. .check-p{
  261. background-color: #0183fa;
  262. color:#fff;
  263. }
  264. }
  265. .hiddenDangerStatisticsEcharts-box{
  266. height:420px;
  267. }
  268. }
  269. </style>