trendChart.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <moduleEnclosure title="趋势图">
  3. <template v-slot:rightce>
  4. <div class="classbtns">
  5. <div @click="cindex = 0" :class="{
  6. select: cindex === 0,
  7. }">
  8. 浏览量(PV)
  9. </div>
  10. <div @click="cindex = 1" :class="{
  11. select: cindex === 1,
  12. }">
  13. 访客量(UV)
  14. </div>
  15. </div>
  16. </template>
  17. <div style="width: 100%; height: 100%">
  18. <div :id="`chartmain_fkell`" style="width: 100%; height: 100%"></div>
  19. </div>
  20. </moduleEnclosure>
  21. </template>
  22. <script>
  23. import { bigGetLarge3 } from '@/api/common.js';
  24. import moduleEnclosure from '@/components/moduleEnclosure.vue';
  25. import * as echarts from 'echarts';
  26. import { csize } from '@/utils/const.js';
  27. export default {
  28. components: {
  29. moduleEnclosure,
  30. },
  31. data() {
  32. return {
  33. cindex: 0,
  34. };
  35. },
  36. mounted() {
  37. this.getbigGetLarge3()
  38. },
  39. beforeUnmount() {
  40. },
  41. watch: {
  42. cindex(){
  43. this.getbigGetLarge3()
  44. }
  45. },
  46. methods: {
  47. getbigGetLarge3() {
  48. bigGetLarge3().then(res => {
  49. this.eac(res.data)
  50. })
  51. },
  52. eac(value) {
  53. var that = this
  54. if (that.myChart) {
  55. that.myChart.dispose();
  56. }
  57. var times = value.map((item) => {
  58. var str1 = item.dstr.split(' ')[0];
  59. return str1.slice(5);
  60. });
  61. var data = value.map((item) => {
  62. return item[["num", "userNum"][this.cindex]];
  63. });
  64. // 计算刻度的间隔
  65. var interval = Math.ceil((Math.max(...data) - Math.min(...data)) / 2); // 确保有 3 个刻度
  66. interval = interval < 1 ? 1 : interval
  67. // 计算 y 轴的最大值和最小值
  68. var maxY = Math.ceil(Math.max(...data) / interval) * interval;
  69. maxY = maxY < 3 ? 3 : maxY
  70. var minY = Math.floor(Math.min(...data) / interval) * interval;
  71. minY = minY < 1 ? 1 : minY
  72. var option = {
  73. tooltip: {
  74. trigger: 'axis',
  75. formatter: function (params) {
  76. var res = '' + params[1].name + ' : ' + params[1].value;
  77. return `<div style="color:#fff;">${res}</div>`;
  78. },
  79. transitionDuration: 0,
  80. backgroundColor: '#092a66',
  81. borderColor: '#0462b5',
  82. borderRadius: 8,
  83. borderWidth: 2,
  84. padding: [5, 10],
  85. axisPointer: {
  86. type: 'line',
  87. lineStyle: {
  88. type: 'dashed',
  89. color: '#8AB1DC',
  90. },
  91. },
  92. },
  93. title: {
  94. text: '',
  95. subtext: '',
  96. },
  97. grid: {
  98. x: csize(40),
  99. y: csize(40),
  100. x2: csize(20),
  101. y2: csize(20),
  102. },
  103. xAxis: {
  104. data: times,
  105. axisLabel: {
  106. interval: Math.floor(times.length / 15),
  107. showMinLabel: true, //是否显示最小 tick 的 label
  108. showMaxLabel: true, //是否显示最大 tick 的 label
  109. fontSize: csize(12),
  110. },
  111. axisTick: {
  112. show: false,
  113. },
  114. axisLine: {
  115. show: false,
  116. symbol: ['none', 'arrow'],
  117. symbolOffset: 12,
  118. lineStyle: {
  119. fontSize: csize(12),
  120. color: '#8AB1DC',
  121. },
  122. },
  123. boundaryGap: false,
  124. },
  125. yAxis: [
  126. {
  127. min: minY,
  128. max: maxY,
  129. interval: interval,
  130. type: 'value',
  131. name: '人(次)',
  132. nameTextStyle: {
  133. fontSize: csize(16),
  134. },
  135. axisLine: {
  136. show: false,
  137. lineStyle: {
  138. color: '#8AB1DC',
  139. },
  140. },
  141. axisLabel: {
  142. margin: 10,
  143. textStyle: {
  144. fontSize: csize(12),
  145. },
  146. },
  147. splitLine: {
  148. lineStyle: {
  149. color: '#364D95',
  150. },
  151. },
  152. axisTick: {
  153. show: false,
  154. },
  155. },
  156. ],
  157. dataZoom: [
  158. {
  159. type: 'inside',
  160. },
  161. ],
  162. series: [
  163. {
  164. // For shadow
  165. type: 'line',
  166. barWidth: 10,
  167. smooth: true, // 设置平滑曲线
  168. symbol: 'none', // 隐藏节点
  169. itemStyle: {
  170. color: 'rgba(0,0,0,0.05)',
  171. },
  172. barGap: '-100%',
  173. barCategoryGap: '40%',
  174. data: data,
  175. animation: false,
  176. },
  177. {
  178. type: 'line',
  179. barWidth: 10,
  180. smooth: true, // 设置平滑曲线
  181. symbol: 'none', // 隐藏节点
  182. itemStyle: {
  183. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  184. { offset: 0, color: '#0efdff' },
  185. { offset: 0.5, color: '#188df0' },
  186. { offset: 1, color: '#188df0' },
  187. ]),
  188. barBorderRadius: 5,
  189. },
  190. areaStyle: { // 设置阴影样式
  191. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ // 线性渐变,从上到下
  192. offset: 0,
  193. color: 'rgba(45,77,149,1)' // 阴影起始颜色
  194. }, { // 线性渐变,从上到下
  195. offset: 0.5,
  196. color: 'rgba(45,77,149,.5)' // 阴影起始颜色
  197. }, {
  198. offset: 1,
  199. color: 'rgba(45,77,149,.2)' // 阴影结束颜色
  200. }])
  201. },
  202. emphasis: {
  203. itemStyle: {
  204. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  205. { offset: 0, color: '#2378f7' },
  206. { offset: 0.7, color: '#2378f7' },
  207. { offset: 1, color: '#0efdff' },
  208. ]),
  209. barBorderRadius: 5,
  210. },
  211. },
  212. data: data,
  213. },
  214. ],
  215. };
  216. that.myChart = new echarts.init(document.getElementById('chartmain_fkell'));
  217. that.myChart.setOption(option);
  218. },
  219. },
  220. };
  221. </script>
  222. <style scoped lang="scss">
  223. .classbtns {
  224. width: 200px;
  225. height: 30px;
  226. display: flex;
  227. flex-direction: row;
  228. justify-content: space-between;
  229. align-items: center;
  230. cursor: pointer;
  231. div:nth-child(1),
  232. div:nth-child(2) {
  233. width: 48%;
  234. height: 100%;
  235. text-align: center;
  236. line-height: 28px;
  237. border: 1px solid #0e72e6;
  238. position: relative;
  239. }
  240. div:nth-child(1) {
  241. border-right: 1px solid #0e72e6;
  242. }
  243. .select {
  244. background: #0e72e6;
  245. color: #bbd4ff;
  246. }
  247. }
  248. ::v-deep .el-carousel__arrow,
  249. ::v-deep .el-carousel__indicators {
  250. display: none;
  251. }
  252. </style>