4.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <template>
  2. <div id="myChartindex4" style="width: 100%; height: 100%;"></div>
  3. </template>
  4. <script>
  5. import { visitDept, visitPerson, deptCollect, PersonCollect } from '../../api'
  6. import echarts from 'echarts'
  7. export default {
  8. name: "Mz_tx_charts",
  9. data() {
  10. return {
  11. dataArr: [],
  12. myChart: null
  13. }
  14. },
  15. methods: {
  16. getArrByKey(data, k) {
  17. let key = k || "value";
  18. let res = [];
  19. if (data) {
  20. data.forEach(function (t) {
  21. res.push(t[key]);
  22. });
  23. }
  24. return res;
  25. },
  26. getMaxValueOfArray(data) {
  27. if (data == null || data.length == 0) {
  28. return 0;
  29. }
  30. let maxValue = data[0].value;
  31. for (let i = 1; i < data.length; i++) {
  32. if (maxValue < data[i].value) {
  33. maxValue = data[i].value;
  34. }
  35. }
  36. return maxValue;
  37. },
  38. // 地区巡访
  39. async draw1() {
  40. const result = await visitDept({}, 'POST');
  41. this.dataArr = result;
  42. const seriesArr = [];
  43. // for(let i = 0; i < this.dataArr.length; i++) {
  44. // const kkArr = new Array(length).fill({});
  45. // kkArr[i] = { value: 100, symbolPosition: 'start' };
  46. // let symbolImage = `image://${require('../../assets/index/y-text-4.png')}`;
  47. // if(i < 4) {
  48. // symbolImage = `image://${require('../../assets/index/y-text-' + (i + 1) + '.png')}`
  49. // }
  50. // seriesArr.push({
  51. // type: 'pictorialBar',
  52. // symbol: symbolImage,
  53. // symbolSize: [24, 24],
  54. // symbolOffset: [-40, -8],
  55. // data: kkArr,
  56. // label: {
  57. // show: true,
  58. // position: 'left',
  59. // offset: [-19, -6],
  60. // color: '#fff',
  61. // fontSize: this.fontSize(0.17),
  62. // formatter: `${ i + 1 }`
  63. // },
  64. // z: 2
  65. // });
  66. // }
  67. if (this.myChart != null) {
  68. this.myChart.clear();
  69. }
  70. this.myChart = this.$echarts.init(document.getElementById('myChartindex4'));
  71. this.myChart.setOption({
  72. grid: {
  73. top: '10%',
  74. bottom: '-18%',
  75. right: '0%',
  76. left: '2%',
  77. containLabel: true
  78. },
  79. xAxis: {
  80. show: false,
  81. max: this.getMaxValueOfArray(this.dataArr)
  82. },
  83. yAxis: [{
  84. triggerEvent: true,
  85. show: true,
  86. inverse: true,
  87. data: this.getArrByKey(this.dataArr, 'label'),
  88. axisLine: {
  89. show: false
  90. },
  91. splitLine: {
  92. show: false
  93. },
  94. axisTick: {
  95. show: false
  96. },
  97. axisLabel: {
  98. show: false
  99. }
  100. }, {
  101. triggerEvent: true,
  102. show: true,
  103. inverse: true,
  104. data: this.getArrByKey(this.dataArr, 'label'),
  105. axisLine: {
  106. show: false
  107. },
  108. splitLine: {
  109. show: false
  110. },
  111. axisTick: {
  112. show: false
  113. },
  114. axisLabel: {
  115. interval: 0,
  116. // shadowOffsetX: '-0px',
  117. // align: 'right',
  118. // verticalAlign: 'bottom',
  119. lineHeight: 0,
  120. fontSize: this.fontSize(0.16),
  121. color: '#fff',
  122. formatter: (value, index) => {
  123. return this.dataArr[index].value + '次';
  124. },
  125. }
  126. }],
  127. series: [{
  128. type: 'bar',
  129. showBackground: true,
  130. barBorderRadius: 50,
  131. yAxisIndex: 0,
  132. data: this.dataArr,
  133. barWidth: 6,
  134. itemStyle: {
  135. color: () => {
  136. return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
  137. offset: 0,
  138. color: '#0071fc'
  139. }, {
  140. offset: 1,
  141. color: '#4be2ec'
  142. }]);
  143. },
  144. barBorderRadius: 30,
  145. },
  146. label: {
  147. normal: {
  148. color: '#00b8ff',
  149. show: true,
  150. position: [0, -this.fontSize(0.18)],
  151. textStyle: {
  152. fontSize: this.fontSize(0.16)
  153. },
  154. formatter: function (a,) {
  155. return a.name;
  156. }
  157. }
  158. }
  159. }, ...seriesArr]
  160. });
  161. },
  162. // 个人巡访
  163. async draw2() {
  164. const result = await visitPerson({}, 'POST');
  165. this.dataArr = result;
  166. const seriesArr = [];
  167. if (this.myChart != null) {
  168. this.myChart.clear();
  169. }
  170. this.myChart = this.$echarts.init(document.getElementById('myChartindex4'));
  171. this.myChart.setOption({
  172. grid: {
  173. top: '10%',
  174. bottom: '-18%',
  175. right: '0%',
  176. left: '2%',
  177. containLabel: true
  178. },
  179. xAxis: {
  180. show: false,
  181. max: this.getMaxValueOfArray(this.dataArr)
  182. },
  183. yAxis: [{
  184. triggerEvent: true,
  185. show: true,
  186. inverse: true,
  187. data: this.getArrByKey(this.dataArr, 'label'),
  188. axisLine: {
  189. show: false
  190. },
  191. splitLine: {
  192. show: false
  193. },
  194. axisTick: {
  195. show: false
  196. },
  197. axisLabel: {
  198. show: false
  199. }
  200. }, {
  201. triggerEvent: true,
  202. show: true,
  203. inverse: true,
  204. data: this.getArrByKey(this.dataArr, 'label'),
  205. axisLine: {
  206. show: false
  207. },
  208. splitLine: {
  209. show: false
  210. },
  211. axisTick: {
  212. show: false
  213. },
  214. axisLabel: {
  215. interval: 0,
  216. // shadowOffsetX: '-50px',
  217. // align: 'right',
  218. // verticalAlign: 'bottom',
  219. // lineHeight: 30,
  220. fontSize: this.fontSize(0.16),
  221. color: '#fff',
  222. formatter: (value, index) => {
  223. return this.dataArr[index].value + '次';
  224. },
  225. }
  226. }],
  227. series: [{
  228. type: 'bar',
  229. showBackground: true,
  230. barBorderRadius: 30,
  231. yAxisIndex: 0,
  232. data: this.dataArr,
  233. barWidth: 6,
  234. itemStyle: {
  235. color: () => {
  236. return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
  237. offset: 0,
  238. color: '#0023ff'
  239. }, {
  240. offset: 1,
  241. color: '#75c6ff'
  242. }]);
  243. },
  244. barBorderRadius: 30,
  245. },
  246. label: {
  247. normal: {
  248. color: '#00b8ff',
  249. show: true,
  250. position: [0, -this.fontSize(0.18)],
  251. textStyle: {
  252. fontSize: this.fontSize(0.16)
  253. },
  254. formatter: function (a,) {
  255. return a.name;
  256. }
  257. }
  258. }
  259. }, ...seriesArr]
  260. });
  261. },
  262. // 地区采集
  263. async draw3() {
  264. const result = await deptCollect({}, 'POST');
  265. this.dataArr = result;
  266. const seriesArr = [];
  267. if (this.myChart != null) {
  268. this.myChart.clear();
  269. }
  270. this.myChart = this.$echarts.init(document.getElementById('myChartindex4'));
  271. this.myChart.setOption({
  272. grid: {
  273. top: '10%',
  274. bottom: '-18%',
  275. right: '0%',
  276. left: '2%',
  277. containLabel: true
  278. },
  279. xAxis: {
  280. show: false,
  281. max: this.getMaxValueOfArray(this.dataArr)
  282. },
  283. yAxis: [{
  284. triggerEvent: true,
  285. show: true,
  286. inverse: true,
  287. data: this.getArrByKey(this.dataArr, 'label'),
  288. axisLine: {
  289. show: false
  290. },
  291. splitLine: {
  292. show: false
  293. },
  294. axisTick: {
  295. show: false
  296. },
  297. axisLabel: {
  298. show: false
  299. }
  300. }, {
  301. triggerEvent: true,
  302. show: true,
  303. inverse: true,
  304. data: this.getArrByKey(this.dataArr, 'label'),
  305. axisLine: {
  306. show: false
  307. },
  308. splitLine: {
  309. show: false
  310. },
  311. axisTick: {
  312. show: false
  313. },
  314. axisLabel: {
  315. interval: 0,
  316. // shadowOffsetX: '-50px',
  317. // align: 'right',
  318. // verticalAlign: 'bottom',
  319. // lineHeight: 30,
  320. fontSize: this.fontSize(0.16),
  321. color: '#fff',
  322. formatter: (value, index) => {
  323. return this.dataArr[index].value + '次';
  324. },
  325. }
  326. }],
  327. series: [{
  328. type: 'bar',
  329. showBackground: true,
  330. barBorderRadius: 30,
  331. yAxisIndex: 0,
  332. data: this.dataArr,
  333. barWidth: 6,
  334. itemStyle: {
  335. color: () => {
  336. return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
  337. offset: 0,
  338. color: '#0023ff'
  339. }, {
  340. offset: 1,
  341. color: '#75c6ff'
  342. }]);
  343. },
  344. barBorderRadius: 30,
  345. },
  346. label: {
  347. normal: {
  348. color: '#00b8ff',
  349. show: true,
  350. position: [0, -this.fontSize(0.18)],
  351. textStyle: {
  352. fontSize: this.fontSize(0.16)
  353. },
  354. formatter: function (a,) {
  355. return a.name;
  356. }
  357. }
  358. }
  359. }, ...seriesArr]
  360. });
  361. },
  362. // 个人采集
  363. async draw4() {
  364. const result = await PersonCollect({}, 'POST');
  365. this.dataArr = result;
  366. const seriesArr = [];
  367. if (this.myChart != null) {
  368. this.myChart.clear();
  369. }
  370. this.myChart = this.$echarts.init(document.getElementById('myChartindex4'));
  371. this.myChart.setOption({
  372. grid: {
  373. top: '10%',
  374. bottom: '-18%',
  375. right: '0%',
  376. left: '2%',
  377. containLabel: true
  378. },
  379. xAxis: {
  380. show: false,
  381. max: this.getMaxValueOfArray(this.dataArr)
  382. },
  383. yAxis: [{
  384. triggerEvent: true,
  385. show: true,
  386. inverse: true,
  387. data: this.getArrByKey(this.dataArr, 'label'),
  388. axisLine: {
  389. show: false
  390. },
  391. splitLine: {
  392. show: false
  393. },
  394. axisTick: {
  395. show: false
  396. },
  397. axisLabel: {
  398. show: false
  399. }
  400. }, {
  401. triggerEvent: true,
  402. show: true,
  403. inverse: true,
  404. data: this.getArrByKey(this.dataArr, 'label'),
  405. axisLine: {
  406. show: false
  407. },
  408. splitLine: {
  409. show: false
  410. },
  411. axisTick: {
  412. show: false
  413. },
  414. axisLabel: {
  415. interval: 0,
  416. // shadowOffsetX: '-50px',
  417. // align: 'right',
  418. // verticalAlign: 'bottom',
  419. // lineHeight: 30,
  420. fontSize: this.fontSize(0.16),
  421. color: '#fff',
  422. formatter: (value, index) => {
  423. return this.dataArr[index].value + '次';
  424. },
  425. }
  426. }],
  427. series: [{
  428. type: 'bar',
  429. showBackground: true,
  430. barBorderRadius: 30,
  431. yAxisIndex: 0,
  432. data: this.dataArr,
  433. barWidth: 6,
  434. itemStyle: {
  435. color: () => {
  436. return new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
  437. offset: 0,
  438. color: '#0023ff'
  439. }, {
  440. offset: 1,
  441. color: '#75c6ff'
  442. }]);
  443. },
  444. barBorderRadius: 30,
  445. },
  446. label: {
  447. normal: {
  448. color: '#00b8ff',
  449. show: true,
  450. position: [0, -this.fontSize(0.18)],
  451. textStyle: {
  452. fontSize: this.fontSize(0.16)
  453. },
  454. formatter: function (a,) {
  455. return a.name;
  456. }
  457. }
  458. }
  459. }, ...seriesArr]
  460. });
  461. },
  462. fontSize(res) {
  463. let clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  464. if (!clientWidth) return;
  465. let fontSize = 100 * (clientWidth / 1920);
  466. return res * fontSize;
  467. }
  468. },
  469. mounted() {
  470. // this.draw4();
  471. }
  472. }
  473. </script>
  474. <style scoped>
  475. </style>