chartsMixin.js 26 KB

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