chartsMixin.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. 'use strict';
  2. const chartsMixin = function () {// 通知消息
  3. return {
  4. data(){
  5. return {
  6. dataTime: '',
  7. yearMonth: []
  8. }
  9. },
  10. computed:{
  11. pickerOptionsH5(){
  12. const _self = this
  13. return {
  14. disabledDate(time) {
  15. // 获取时间选择器的年份信息
  16. const timeYear = time.getFullYear(); // 获取时间选择器的年份
  17. // 获取时间选择器的月份信息
  18. let timeMonth = time.getMonth() + 1; // 获取时间选择器的月份
  19. if (timeMonth >= 1 && timeMonth <= 9) {
  20. timeMonth = "0" + timeMonth; // 如果月份小于10,前面补0
  21. }
  22. const elTimeData = timeYear.toString() + timeMonth.toString(); // 组合年份和月份字符串
  23. // 根据需要禁用多个月份,这里禁用了2021年的10月和11月作为选择范围
  24. return _self.yearMonth.includes(elTimeData)
  25. }
  26. }
  27. },
  28. pickerOptions(){
  29. const _self = this
  30. return {
  31. disabledDate(time) {
  32. // 获取时间选择器的年份信息
  33. const timeYear = time.getFullYear(); // 获取时间选择器的年份
  34. // 获取时间选择器的月份信息
  35. let timeMonth = time.getMonth() + 1; // 获取时间选择器的月份
  36. if (timeMonth >= 1 && timeMonth <= 9) {
  37. timeMonth = "0" + timeMonth; // 如果月份小于10,前面补0
  38. }
  39. const elTimeData = timeYear.toString() + timeMonth.toString(); // 组合年份和月份字符串
  40. // 根据需要禁用多个月份,这里禁用了2021年的10月和11月作为选择范围
  41. return _self.yearMonth.includes(elTimeData)
  42. },
  43. shortcuts: [{
  44. text: '本月',
  45. onClick(picker) {
  46. picker.$emit('pick', [new Date(), new Date()]);
  47. }
  48. }, {
  49. text: '今年至今',
  50. onClick(picker) {
  51. const end = new Date();
  52. const start = new Date(new Date().getFullYear(), 0);
  53. picker.$emit('pick', [start, end]);
  54. }
  55. }, {
  56. text: '最近六个月',
  57. onClick(picker) {
  58. const end = new Date();
  59. const start = new Date();
  60. start.setMonth(start.getMonth() - 6);
  61. picker.$emit('pick', [start, end]);
  62. }
  63. }]
  64. }
  65. }
  66. },
  67. methods: {
  68. chartWordCloud(data){// 词云
  69. let myChart = echarts.init(document.getElementById('myChart0'));
  70. let option = {
  71. title: {text: '关键词云图'},
  72. tooltip: {trigger: 'item'},
  73. series: [{
  74. type: 'wordCloud',
  75. shape: 'circle',
  76. keepAspect: false,
  77. maskImage: '',
  78. left: 'center',
  79. top: 'center',
  80. width: '90%',
  81. height: '85%',
  82. right: null,
  83. bottom: null,
  84. sizeRange: [12, 60],
  85. rotationRange: [-90, 90],
  86. rotationStep: 45,
  87. gridSize: 10,
  88. drawOutOfBound: false,
  89. shrinkToFit: false,
  90. layoutAnimation: true,
  91. textStyle: {
  92. fontFamily: 'sans-serif',
  93. fontWeight: 'bold',
  94. color: function () {
  95. // Random color
  96. return 'rgb(' + [
  97. Math.round(Math.random() * 160),
  98. Math.round(Math.random() * 160),
  99. Math.round(Math.random() * 160)
  100. ].join(',') + ')';
  101. }
  102. },
  103. emphasis: {
  104. focus: 'self',
  105. textStyle: {
  106. textShadowBlur: 10,
  107. textShadowColor: '#333'
  108. }
  109. },
  110. data:data
  111. }]
  112. }
  113. myChart.setOption(option)
  114. window.addEventListener("resize", function() {
  115. myChart.resize()
  116. })
  117. },
  118. //公众号推文
  119. chartWechats(data,shopName){
  120. let myChart = echarts.init(document.getElementById('myChart1'))
  121. let option = {
  122. title: {
  123. text: `推文数据`
  124. },
  125. tooltip: {
  126. trigger: 'axis',
  127. axisPointer: {
  128. type: 'shadow'
  129. }
  130. },
  131. legend: {},
  132. grid: {
  133. left: '3%',
  134. right: '4%',
  135. bottom: '3%',
  136. containLabel: true
  137. },
  138. xAxis: {
  139. type: 'category',
  140. data: data.names
  141. },
  142. yAxis: {
  143. type: 'value',
  144. boundaryGap: [0, 0.01],
  145. },
  146. series: [
  147. {
  148. name: '点击量',
  149. type: 'line',
  150. color:['#A294FF'],
  151. data: data.values
  152. },
  153. {
  154. name: '展现量',
  155. type: 'line',
  156. color:['#45CCF8'],
  157. data: data.backupsValues
  158. }
  159. ]
  160. };
  161. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  162. },
  163. chartIntention(data,shopName){ // 采美全渠道展现量
  164. let myChart = echarts.init(document.getElementById('myChart2'))
  165. let option = {
  166. title: {
  167. text: ` 采美全渠道展现量`
  168. },
  169. tooltip: {
  170. trigger: 'axis',
  171. axisPointer: {
  172. type: 'shadow' //
  173. }
  174. },
  175. legend: {
  176. orient: 'horizontal',
  177. right: '0%',
  178. top:'0%',
  179. itemGap: 10, // 这里可以设置图例每项之间的间隔
  180. itemWidth: 20, // 这里可以设置图例标记的宽度
  181. itemHeight: 14, // 这里可以设置图例标记的高度
  182. textStyle: {
  183. fontSize: 12,
  184. }
  185. },
  186. grid: {
  187. left: '3%',
  188. right: '4%',
  189. bottom: '3%',
  190. containLabel: true
  191. },
  192. xAxis: {
  193. type: 'category',
  194. data: data.names
  195. },
  196. yAxis: {
  197. type: 'value'
  198. },
  199. series: [
  200. {
  201. type: 'bar',
  202. stack: 'total',
  203. label: {
  204. show: false
  205. },
  206. emphasis: {
  207. focus: 'series'
  208. },
  209. barGap:'55%',
  210. barCategoryGap:'55%',
  211. data: data.values,
  212. itemStyle: {
  213. color: function(params) {
  214. // params 是当前柱状图的数据点信息对象
  215. const colorList = ['#07c160','#d48265','#fa5151','#1890ff'];
  216. return colorList[params.dataIndex]
  217. }
  218. }
  219. }
  220. ]
  221. };
  222. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  223. },
  224. // 采美全渠道点击量
  225. chartAllVisits(data,shopName){
  226. let myChart = echarts.init(document.getElementById('myChart3'))
  227. let option = {
  228. title: {
  229. text: ` 采美全渠道点击量`
  230. },
  231. tooltip: {
  232. trigger: 'axis',
  233. axisPointer: {
  234. type: 'shadow' //
  235. }
  236. },
  237. legend: {
  238. orient: 'horizontal',
  239. right: '0%',
  240. top:'0%',
  241. itemGap: 10, // 这里可以设置图例每项之间的间隔
  242. itemWidth: 20, // 这里可以设置图例标记的宽度
  243. itemHeight: 14, // 这里可以设置图例标记的高度
  244. textStyle: {
  245. fontSize: 12,
  246. }
  247. },
  248. grid: {
  249. left: '3%',
  250. right: '4%',
  251. bottom: '3%',
  252. containLabel: true
  253. },
  254. xAxis: {
  255. type: 'category',
  256. data: data.names
  257. },
  258. yAxis: {
  259. type: 'value',
  260. },
  261. series: [
  262. {
  263. type: 'bar',
  264. stack: 'total',
  265. label: {
  266. show: false
  267. },
  268. emphasis: {
  269. focus: 'series'
  270. },
  271. barGap:'55%',
  272. barCategoryGap:'55%',
  273. data: data.values,
  274. itemStyle: {
  275. color: function(params) {
  276. // params 是当前柱状图的数据点信息对象
  277. const colorList = ['#07c160','#d48265','#fa5151','#1890ff'];
  278. return colorList[params.dataIndex]
  279. }
  280. }
  281. }
  282. ]
  283. };
  284. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  285. },
  286. chartProportion(data,shopName){ // 渠道来源占比
  287. let myChart = echarts.init(document.getElementById('myChart4'))
  288. let option = {
  289. title: {
  290. text: ` 访问用户渠道来源占比`
  291. },
  292. tooltip: {
  293. trigger: 'item'
  294. },
  295. legend: {
  296. orient: 'horizontal',
  297. top:'bottom'
  298. },
  299. series: [
  300. {
  301. name: '',
  302. color:['#45CCF8','#4880FF','#1CC170','#FF726E'],
  303. type: 'pie',
  304. radius: ['35%', '25%'],
  305. center: ['50%', '50%'],
  306. avoidLabelOverlap: false,
  307. label: {
  308. show: true,
  309. formatter(param) {
  310. // correct the percentage
  311. return param.name + ' (' + param.value + '%)';
  312. }
  313. },
  314. emphasis: {
  315. itemStyle: {
  316. shadowBlur: 10,
  317. shadowOffsetX: 0,
  318. shadowColor: 'rgba(0, 0, 0, 0.5)'
  319. }
  320. },
  321. data:data
  322. }
  323. ]
  324. };
  325. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  326. },
  327. // 采美站内访问量
  328. chartStationVisits(data,shopName){
  329. let myChart = echarts.init(document.getElementById('myChart5'))
  330. let option = {
  331. title: {
  332. text: ` 品牌整体访问量`
  333. },
  334. tooltip: {
  335. trigger: 'axis',
  336. axisPointer: {
  337. type: 'shadow' //
  338. }
  339. },
  340. legend: {
  341. orient: 'horizontal',
  342. right: '0%',
  343. top:'0%',
  344. itemGap: 10, // 这里可以设置图例每项之间的间隔
  345. itemWidth: 20, // 这里可以设置图例标记的宽度
  346. itemHeight: 14, // 这里可以设置图例标记的高度
  347. textStyle: {
  348. fontSize: 12,
  349. },
  350. },
  351. grid: {
  352. left: '3%',
  353. right: '4%',
  354. bottom: '3%',
  355. containLabel: true
  356. },
  357. xAxis: {
  358. type: 'category',
  359. data: data.names
  360. },
  361. yAxis: {
  362. type: 'value',
  363. },
  364. series: [
  365. {
  366. type: 'bar',
  367. stack: 'total',
  368. label: {
  369. show: false
  370. },
  371. emphasis: {
  372. focus: 'series'
  373. },
  374. barGap:'80%',
  375. barCategoryGap:'80%',
  376. data: data.values,
  377. itemStyle: {
  378. color: function(params) {
  379. // params 是当前柱状图的数据点信息对象
  380. const colorList = ['#07c160','#1890ff'];
  381. return colorList[params.dataIndex]
  382. }
  383. }
  384. }
  385. ]
  386. };
  387. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  388. },
  389. chartVisitTimes(data,shopName){ // 页面平均访问时长top5
  390. let myChart = echarts.init(document.getElementById('myChart6'))
  391. let option = {
  392. title: {
  393. text: ` 访问页面平均时长top5(单位:秒)`,
  394. left: 'left'
  395. },
  396. tooltip: {
  397. trigger: 'axis',
  398. color:'#FE8645',
  399. formatter: function(params) { // 格式化 tooltip 内容
  400. return '访问时长:'+ params[0].value + 's'
  401. },
  402. axisPointer: {
  403. type: 'shadow'
  404. }
  405. },
  406. legend: {
  407. show:false,
  408. },
  409. grid: {
  410. left: '3%',
  411. right: '4%',
  412. bottom: '3%',
  413. containLabel: true
  414. },
  415. xAxis: {
  416. type: 'category',
  417. data: data.names
  418. },
  419. yAxis: {
  420. type: 'value',
  421. splitLine:{
  422. show: true,
  423. lineStyle:{
  424. opacity:0.8,
  425. color:'#E1E1E1',
  426. type:'dashed'
  427. }
  428. },
  429. boundaryGap: [0, 0.01],
  430. axisLabel:{
  431. show: true,
  432. textStyle:{
  433. color: '#999999', //更改坐标轴文字颜色
  434. fontSize : 14, //更改坐标轴文字大小
  435. }
  436. },
  437. axisTick: {//轴网格,在xAxis或yAxis根下
  438. lineStyle:{
  439. width:1,
  440. color:'#E1E1E1',
  441. type:'dashed'
  442. }
  443. }
  444. },
  445. series: [
  446. {
  447. type: 'line',
  448. name: '访问时长',
  449. data: data.values,
  450. color:'#4880FF',
  451. label: {
  452. show: true
  453. },
  454. areaStyle: {
  455. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  456. {
  457. offset: 0,
  458. color: 'rgb(72,128,255)'
  459. },
  460. {
  461. offset: 1,
  462. color: 'rgb(68,92,207)'
  463. }
  464. ])
  465. }
  466. }
  467. ]
  468. };
  469. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  470. },
  471. // 咨询用户月度分布
  472. chartLeadUserMonthly(data,shopName){
  473. let myChart = echarts.init(document.getElementById('myChart7'))
  474. let option = {
  475. title: {
  476. text: ` 咨询用户月度数量(单位:个)`
  477. },
  478. tooltip: {
  479. trigger: 'axis',
  480. axisPointer: {
  481. type: 'shadow' //
  482. }
  483. },
  484. legend: {
  485. orient: 'horizontal',
  486. right: '0%',
  487. top:'0%',
  488. show:false,
  489. itemGap: 10, // 这里可以设置图例每项之间的间隔
  490. itemWidth: 20, // 这里可以设置图例标记的宽度
  491. itemHeight: 14, // 这里可以设置图例标记的高度
  492. textStyle: {
  493. fontSize: 12,
  494. }
  495. },
  496. grid: {
  497. left: '3%',
  498. right: '4%',
  499. bottom: '3%',
  500. containLabel: true
  501. },
  502. xAxis: {
  503. type: 'value',
  504. },
  505. yAxis: {
  506. type: 'category',
  507. data: data.names
  508. },
  509. series: [
  510. {
  511. name: '咨询用户月度数量:',
  512. type: 'bar',
  513. stack: 'total',
  514. label: {
  515. show: true
  516. },
  517. emphasis: {
  518. focus: 'series'
  519. },
  520. barGap:'80%',
  521. barCategoryGap:'80%',
  522. color:'#4880FF',
  523. data: data.values
  524. }
  525. ]
  526. };
  527. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  528. },
  529. chartChannels(data,shopName){// 咨询用户地狱分布
  530. let myChart = echarts.init(document.getElementById('myChart8'))
  531. let option = {
  532. title: {
  533. text: ` 访问用户地域分布`
  534. },
  535. tooltip: {
  536. trigger: 'item'
  537. },
  538. visualMap: {
  539. min: 0,
  540. max: 1000,
  541. left: 'left',
  542. top: 'bottom',
  543. text: ['高', '低'], // 文本,默认为数值文本
  544. calculable: true,
  545. inRange: {
  546. color: ['#e0ffff', '#006edd']
  547. }
  548. },
  549. series: [
  550. {
  551. name: '中国',
  552. type: 'map',
  553. mapType: 'china', // 设置地图类型为中国省份地图
  554. roam: false, // 禁止缩放和平移操作
  555. label: {
  556. show: true,
  557. // formatter(param) {
  558. // // correct the percentage
  559. // return param.name + ' (' + param.value + '%)';
  560. // }
  561. },
  562. data: data,
  563. itemStyle:{
  564. fontSize: 14,
  565. color:'#FE8645'
  566. }
  567. }
  568. ]
  569. };
  570. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  571. },
  572. chartUrbanize(data,shopName){ // 用户类型分布
  573. let myChart = echarts.init(document.getElementById('myChart9'))
  574. let option = {
  575. title: {
  576. text: ` 访问用户类型分布`,
  577. left: 'left'
  578. },
  579. tooltip: {
  580. trigger: 'item'
  581. },
  582. legend: {
  583. orient: 'horizontal',
  584. top:'bottom'
  585. },
  586. series: [
  587. {
  588. name: '',
  589. color:['#45CCF8','#4880FF','#FE8645'],
  590. type: 'pie',
  591. radius: ['35%', '25%'],
  592. center: ['50%', '50%'],
  593. avoidLabelOverlap: false,
  594. label: {
  595. show: true,
  596. formatter(param) {
  597. // correct the percentage
  598. return param.name + ' (' + param.value + '%)';
  599. }
  600. },
  601. emphasis: {
  602. itemStyle: {
  603. shadowBlur: 10,
  604. shadowOffsetX: 0,
  605. shadowColor: 'rgba(0, 0, 0, 0.5)'
  606. }
  607. },
  608. data: data
  609. }
  610. ]
  611. };
  612. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  613. },
  614. chartUserIdentity(data,shopName){ // 用户身份分布
  615. let myChart = echarts.init(document.getElementById('myChart10'))
  616. let option = {
  617. title: {
  618. text: ` 访问用户身份分布`,
  619. left: 'left'
  620. },
  621. tooltip: {
  622. trigger: 'item'
  623. },
  624. legend: {
  625. orient: 'horizontal',
  626. top:'bottom'
  627. },
  628. series: [
  629. {
  630. name: '',
  631. color:['#45CCF8','#4880FF','#1CC170'],
  632. type: 'pie',
  633. radius: ['35%', '25%'],
  634. center: ['50%', '50%'],
  635. avoidLabelOverlap: false,
  636. label: {
  637. show: true,
  638. formatter(param) {
  639. // correct the percentage
  640. return param.name + ' (' + param.value + '%)';
  641. }
  642. },
  643. emphasis: {
  644. itemStyle: {
  645. shadowBlur: 10,
  646. shadowOffsetX: 0,
  647. shadowColor: 'rgba(0, 0, 0, 0.5)'
  648. }
  649. },
  650. data: data
  651. }
  652. ]
  653. };
  654. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  655. },
  656. chartIntentions(data,shopName){ // 用户意向分布
  657. let myChart = echarts.init(document.getElementById('myChart11'))
  658. let option = {
  659. title: {
  660. text: ` 用户意向分布`,
  661. left: 'left'
  662. },
  663. tooltip: {
  664. trigger: 'item'
  665. },
  666. legend: {
  667. orient: 'horizontal',
  668. top:'bottom'
  669. },
  670. series: [
  671. {
  672. name: '',
  673. color:['#45CCF8','#4880FF','#1CC170','#FF726E'],
  674. type: 'pie',
  675. radius: ['35%', '25%'],
  676. center: ['50%', '50%'],
  677. avoidLabelOverlap: false,
  678. label: {
  679. show: true,
  680. formatter(param) {
  681. // correct the percentage
  682. return param.name + ' (' + param.value + '%)';
  683. }
  684. },
  685. emphasis: {
  686. itemStyle: {
  687. shadowBlur: 10,
  688. shadowOffsetX: 0,
  689. shadowColor: 'rgba(0, 0, 0, 0.5)'
  690. }
  691. },
  692. data:data.series
  693. }
  694. ]
  695. };
  696. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  697. }
  698. },
  699. };
  700. }();