trendChart.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <template>
  2. <moduleEnclosure title="趋势图">
  3. <template v-slot:rightce>
  4. <div class="classbtns">
  5. <div
  6. @click="cindex = 0"
  7. :class="{
  8. select: cindex === 0,
  9. }"
  10. >
  11. 浏览量
  12. </div>
  13. <div
  14. @click="cindex = 1"
  15. :class="{
  16. select: cindex === 1,
  17. }"
  18. >
  19. 访客量
  20. </div>
  21. </div>
  22. </template>
  23. <el-carousel
  24. height="100%"
  25. style="width: 100%; height: 100%"
  26. ref="elCarousel"
  27. :autoplay="false"
  28. >
  29. <el-carousel-item v-for="(item, index) in 2" :key="index">
  30. <div style="width: 100%; height: 100%">
  31. <div
  32. :id="`chartmain_${item}`"
  33. style="width: 100%; height: 100%"
  34. ></div>
  35. </div>
  36. </el-carousel-item>
  37. </el-carousel>
  38. </moduleEnclosure>
  39. </template>
  40. <script>
  41. import moduleEnclosure from '@/components/moduleEnclosure.vue';
  42. import * as echarts from 'echarts';
  43. import { getQuery12 } from '@/api/bigView.js';
  44. import { csize } from '@/utils/const.js';
  45. let myChart, myChart2;
  46. export default {
  47. components: {
  48. moduleEnclosure,
  49. },
  50. data() {
  51. return {
  52. cindex: -1,
  53. myChart: null,
  54. myChart2: null,
  55. };
  56. },
  57. mounted() {
  58. this.timeId = getQuery12((res) => {
  59. this.eac(res.data);
  60. this.init_myChart2(res.data);
  61. }, 70000);
  62. this.cindex = 0;
  63. },
  64. beforeUnmount() {
  65. this.timeId();
  66. },
  67. watch: {
  68. cindex(newVal, oldValue) {
  69. if (oldValue !== -1) {
  70. this.$refs.elCarousel.next();
  71. }
  72. if (this.timed) {
  73. clearTimeout(this.timed);
  74. }
  75. this.timed = setTimeout(() => {
  76. this.cindex = this.cindex ? 0 : 1;
  77. }, 30000);
  78. },
  79. },
  80. methods: {
  81. eac(value) {
  82. var times = value.map((item) => {
  83. var str1 = item.ddate.split(' ')[0];
  84. return str1.slice(5);
  85. });
  86. var data = value.map((item) => {
  87. return item.badapp;
  88. });
  89. var option = {
  90. tooltip: {
  91. trigger: 'axis',
  92. formatter: function (params) {
  93. var res = '' + params[1].name + ' : ' + params[1].value;
  94. return `<div style="color:#fff;">${res}</div>`;
  95. },
  96. transitionDuration: 0,
  97. backgroundColor: '#092a66',
  98. borderColor: '#0462b5',
  99. borderRadius: 8,
  100. borderWidth: 2,
  101. padding: [5, 10],
  102. axisPointer: {
  103. type: 'line',
  104. lineStyle: {
  105. type: 'dashed',
  106. color: '#8AB1DC',
  107. },
  108. },
  109. },
  110. title: {
  111. text: '',
  112. subtext: '',
  113. },
  114. grid: {
  115. x: csize(65),
  116. y: csize(40),
  117. x2: csize(30),
  118. y2: csize(30),
  119. },
  120. xAxis: {
  121. data: times,
  122. axisLabel: {
  123. interval: Math.floor(times.length / 15),
  124. showMinLabel: true, //是否显示最小 tick 的 label
  125. showMaxLabel: true, //是否显示最大 tick 的 label
  126. fontSize: csize(12),
  127. },
  128. axisTick: {
  129. show: false,
  130. },
  131. axisLine: {
  132. show: false,
  133. symbol: ['none', 'arrow'],
  134. symbolOffset: 12,
  135. lineStyle: {
  136. fontSize: csize(12),
  137. color: '#8AB1DC',
  138. },
  139. },
  140. },
  141. yAxis: [
  142. {
  143. type: 'value',
  144. name: '单位(单)',
  145. nameTextStyle: {
  146. fontSize: csize(16),
  147. },
  148. axisLine: {
  149. show: false,
  150. lineStyle: {
  151. color: '#8AB1DC',
  152. },
  153. },
  154. axisLabel: {
  155. margin: 10,
  156. textStyle: {
  157. fontSize: csize(12),
  158. },
  159. },
  160. splitLine: {
  161. lineStyle: {
  162. color: '#364D95',
  163. },
  164. },
  165. axisTick: {
  166. show: false,
  167. },
  168. },
  169. ],
  170. dataZoom: [
  171. {
  172. type: 'inside',
  173. },
  174. ],
  175. series: [
  176. {
  177. // For shadow
  178. type: 'bar',
  179. barWidth: 10,
  180. itemStyle: {
  181. color: 'rgba(0,0,0,0.05)',
  182. },
  183. barGap: '-100%',
  184. barCategoryGap: '40%',
  185. data: data,
  186. animation: false,
  187. },
  188. {
  189. type: 'bar',
  190. barWidth: 10,
  191. itemStyle: {
  192. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  193. { offset: 0, color: '#0efdff' },
  194. { offset: 0.5, color: '#188df0' },
  195. { offset: 1, color: '#188df0' },
  196. ]),
  197. barBorderRadius: 5,
  198. },
  199. emphasis: {
  200. itemStyle: {
  201. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  202. { offset: 0, color: '#2378f7' },
  203. { offset: 0.7, color: '#2378f7' },
  204. { offset: 1, color: '#0efdff' },
  205. ]),
  206. barBorderRadius: 5,
  207. },
  208. },
  209. data: data,
  210. },
  211. ],
  212. };
  213. if (myChart) {
  214. myChart.dispose();
  215. }
  216. myChart = new echarts.init(document.getElementById('chartmain_1'));
  217. myChart.setOption(option);
  218. },
  219. init_myChart2(value) {
  220. var times = value.map((item) => {
  221. var str1 = item.ddate.split(' ')[0];
  222. return str1.slice(5);
  223. });
  224. var data = value.map((item) => {
  225. return item.goodrate;
  226. });
  227. var data1 = value.map((item) => {
  228. return item.insrate;
  229. });
  230. var data2 = value.map((item) => {
  231. return item.reprate;
  232. });
  233. if (myChart2) {
  234. myChart2.dispose();
  235. }
  236. myChart2 = new echarts.init(document.getElementById('chartmain_2'));
  237. myChart2.setOption({
  238. tooltip: {
  239. trigger: 'axis',
  240. formatter: function (params) {
  241. var res = '';
  242. for (var i = 0, l = params.length; i < l; i++) {
  243. res +=
  244. '' + params[i].seriesName + ' : ' + params[i].value + '<br>';
  245. }
  246. return `<div style="color:#fff;">${res}</div>`;
  247. },
  248. transitionDuration: 0,
  249. backgroundColor: '#092a66',
  250. borderColor: '#0462b5',
  251. borderRadius: 8,
  252. borderWidth: 2,
  253. padding: [5, 10],
  254. axisPointer: {
  255. type: 'line',
  256. lineStyle: {
  257. type: 'dashed',
  258. color: '#8AB1DC',
  259. },
  260. },
  261. },
  262. legend: {
  263. icon: 'circle',
  264. itemWidth: 8,
  265. itemHeight: 8,
  266. itemGap: 10,
  267. top: '16',
  268. right: '10',
  269. data: ['好评率', '安装评价率', '维修评价率'],
  270. textStyle: {
  271. fontSize: csize(16),
  272. color: '#8AB1DC',
  273. },
  274. },
  275. grid: {
  276. x: csize(65),
  277. y: csize(50),
  278. x2: csize(30),
  279. y2: csize(30),
  280. },
  281. xAxis: [
  282. {
  283. type: 'category',
  284. boundaryGap: false,
  285. axisLabel: {
  286. interval: Math.floor(times.length / 15),
  287. showMinLabel: true, //是否显示最小 tick 的 label
  288. showMaxLabel: true, //是否显示最大 tick 的 label
  289. fontSize: csize(12),
  290. },
  291. axisLine: {
  292. show: false,
  293. lineStyle: {
  294. color: '#8AB1DC',
  295. },
  296. },
  297. axisTick: {
  298. show: false,
  299. },
  300. data: times,
  301. },
  302. ],
  303. yAxis: [
  304. {
  305. type: 'value',
  306. name: '单位(%)',
  307. nameTextStyle: {
  308. fontSize: csize(16),
  309. },
  310. axisLine: {
  311. show: false,
  312. lineStyle: {
  313. color: '#8AB1DC',
  314. },
  315. },
  316. axisLabel: {
  317. margin: 10,
  318. textStyle: {
  319. fontSize: csize(12),
  320. },
  321. },
  322. splitLine: {
  323. lineStyle: {
  324. color: '#364D95',
  325. },
  326. },
  327. axisTick: {
  328. show: false,
  329. },
  330. },
  331. ],
  332. series: [
  333. {
  334. name: '好评率',
  335. type: 'line',
  336. smooth: true,
  337. showSymbol: false,
  338. lineStyle: {
  339. normal: {
  340. width: 2,
  341. },
  342. },
  343. areaStyle: {
  344. normal: {
  345. color: new echarts.graphic.LinearGradient(
  346. 0,
  347. 0,
  348. 0,
  349. 1,
  350. [
  351. {
  352. offset: 0,
  353. color: 'rgba(137, 189, 27, 0.3)',
  354. },
  355. {
  356. offset: 0.8,
  357. color: 'rgba(137, 189, 27, 0)',
  358. },
  359. ],
  360. false
  361. ),
  362. shadowColor: 'rgba(0, 0, 0, 0.1)',
  363. shadowBlur: 10,
  364. },
  365. },
  366. itemStyle: {
  367. normal: {
  368. color: '#F34799',
  369. },
  370. },
  371. data: data,
  372. },
  373. {
  374. name: '安装评价率',
  375. type: 'line',
  376. smooth: true,
  377. showSymbol: false,
  378. lineStyle: {
  379. normal: {
  380. width: 2,
  381. },
  382. },
  383. areaStyle: {
  384. normal: {
  385. color: new echarts.graphic.LinearGradient(
  386. 0,
  387. 0,
  388. 0,
  389. 1,
  390. [
  391. {
  392. offset: 0,
  393. color: 'rgba(137, 189, 27, 0.3)',
  394. },
  395. {
  396. offset: 0.8,
  397. color: 'rgba(137, 189, 27, 0)',
  398. },
  399. ],
  400. false
  401. ),
  402. shadowColor: 'rgba(0, 0, 0, 0.1)',
  403. shadowBlur: 10,
  404. },
  405. },
  406. itemStyle: {
  407. normal: {
  408. color: '#1cc840',
  409. },
  410. },
  411. data: data1,
  412. },
  413. {
  414. name: '维修评价率',
  415. type: 'line',
  416. smooth: true,
  417. showSymbol: false,
  418. lineStyle: {
  419. normal: {
  420. width: 2,
  421. },
  422. },
  423. areaStyle: {
  424. normal: {
  425. color: new echarts.graphic.LinearGradient(
  426. 0,
  427. 0,
  428. 0,
  429. 1,
  430. [
  431. {
  432. offset: 0,
  433. color: 'rgba(0, 136, 212, 0.3)',
  434. },
  435. {
  436. offset: 0.8,
  437. color: 'rgba(0, 136, 212, 0)',
  438. },
  439. ],
  440. false
  441. ),
  442. shadowColor: 'rgba(0, 0, 0, 0.1)',
  443. shadowBlur: 10,
  444. },
  445. },
  446. itemStyle: {
  447. normal: {
  448. color: '#43bbfb',
  449. },
  450. },
  451. data: data2,
  452. },
  453. ],
  454. });
  455. },
  456. },
  457. };
  458. </script>
  459. <style scoped lang="scss">
  460. .classbtns {
  461. width: 160px;
  462. height: 28px;
  463. display: flex;
  464. flex-direction: row;
  465. align-items: center;
  466. border: 2px solid #0e72e6;
  467. cursor: pointer;
  468. div {
  469. width: 50%;
  470. height: 100%;
  471. text-align: center;
  472. line-height: 28px;
  473. }
  474. div:nth-child(1) {
  475. border-right: 2px solid #0e72e6;
  476. }
  477. .select {
  478. background: #0e72e6;
  479. color: #bbd4ff;
  480. }
  481. }
  482. ::v-deep .el-carousel__arrow,
  483. ::v-deep .el-carousel__indicators {
  484. display: none;
  485. }
  486. </style>