chartMixin.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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: `【${shopName}】公众号推文数据`
  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.xAxis
  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.yAxis.yuedu
  93. },
  94. {
  95. name: '展现量',
  96. type: 'line',
  97. color:['#45CCF8'],
  98. data: data.yAxis.chuda
  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: `【${shopName}】采美全渠道展现量`
  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. data: ['公众号', '微博', '小红书','其他渠道']
  127. },
  128. grid: {
  129. left: '3%',
  130. right: '4%',
  131. bottom: '3%',
  132. containLabel: true
  133. },
  134. xAxis: {
  135. type: 'category',
  136. data: data.xAxis
  137. },
  138. yAxis: {
  139. type: 'value',
  140. },
  141. series: [
  142. {
  143. name: '公众号',
  144. type: 'bar',
  145. stack: 'total',
  146. label: {
  147. show: false
  148. },
  149. emphasis: {
  150. focus: 'series'
  151. },
  152. barGap:'60%',
  153. barCategoryGap:'60%',
  154. data: data.yAxis.general
  155. },
  156. {
  157. name: '微博',
  158. type: 'bar',
  159. stack: 'total',
  160. label: {
  161. show: false
  162. },
  163. emphasis: {
  164. focus: 'series'
  165. },
  166. barGap:'60%',
  167. barCategoryGap:'60%',
  168. data: data.yAxis.twitter
  169. },
  170. {
  171. name: '小红书',
  172. type: 'bar',
  173. stack: 'total',
  174. label: {
  175. show: false
  176. },
  177. emphasis: {
  178. focus: 'series'
  179. },
  180. barGap:'60%',
  181. barCategoryGap:'60%',
  182. data: data.yAxis.redBook
  183. },
  184. {
  185. name: '其他渠道',
  186. type: 'bar',
  187. stack: 'total',
  188. label: {
  189. show: false
  190. },
  191. emphasis: {
  192. focus: 'series'
  193. },
  194. barGap:'60%',
  195. barCategoryGap:'60%',
  196. data: data.yAxis.other
  197. }
  198. ]
  199. };
  200. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  201. },
  202. // 全渠道访问用户数量
  203. chartAllVisits(data,shopName){
  204. let myChart = echarts.init(document.getElementById('myChart3'))
  205. let option = {
  206. title: {
  207. text: `【${shopName}】采美全渠道点击量`
  208. },
  209. tooltip: {
  210. trigger: 'axis',
  211. axisPointer: {
  212. type: 'shadow' //
  213. }
  214. },
  215. legend: {
  216. orient: 'horizontal',
  217. right: '0%',
  218. top:'0%',
  219. itemGap: 10, // 这里可以设置图例每项之间的间隔
  220. itemWidth: 20, // 这里可以设置图例标记的宽度
  221. itemHeight: 14, // 这里可以设置图例标记的高度
  222. textStyle: {
  223. fontSize: 12,
  224. },
  225. data: ['公众号', '微博', '小红书','其他渠道']
  226. },
  227. grid: {
  228. left: '3%',
  229. right: '4%',
  230. bottom: '3%',
  231. containLabel: true
  232. },
  233. xAxis: {
  234. type: 'category',
  235. data: data.xAxis
  236. },
  237. yAxis: {
  238. type: 'value',
  239. },
  240. series: [
  241. {
  242. name: '公众号',
  243. type: 'bar',
  244. stack: 'total',
  245. label: {
  246. show: false
  247. },
  248. emphasis: {
  249. focus: 'series'
  250. },
  251. barGap:'60%',
  252. barCategoryGap:'60%',
  253. data: data.yAxis.general
  254. },
  255. {
  256. name: '微博',
  257. type: 'bar',
  258. stack: 'total',
  259. label: {
  260. show: false
  261. },
  262. emphasis: {
  263. focus: 'series'
  264. },
  265. barGap:'60%',
  266. barCategoryGap:'60%',
  267. data: data.yAxis.twitter
  268. },
  269. {
  270. name: '小红书',
  271. type: 'bar',
  272. stack: 'total',
  273. label: {
  274. show: false
  275. },
  276. emphasis: {
  277. focus: 'series'
  278. },
  279. barGap:'60%',
  280. barCategoryGap:'60%',
  281. data: data.yAxis.redBook
  282. },
  283. {
  284. name: '其他渠道',
  285. type: 'bar',
  286. stack: 'total',
  287. label: {
  288. show: false
  289. },
  290. emphasis: {
  291. focus: 'series'
  292. },
  293. barGap:'60%',
  294. barCategoryGap:'60%',
  295. data: data.yAxis.other
  296. }
  297. ]
  298. };
  299. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  300. },
  301. chartProportion(data,shopName){ // 渠道来源占比
  302. let myChart = echarts.init(document.getElementById('myChart4'))
  303. let option = {
  304. title: {
  305. text: `【${shopName}】访问用户渠道来源占比`
  306. },
  307. legend: {
  308. orient: 'horizontal',
  309. right: '0%',
  310. top:'0%',
  311. itemGap: 10, // 这里可以设置图例每项之间的间隔
  312. itemWidth: 20, // 这里可以设置图例标记的宽度
  313. itemHeight: 14, // 这里可以设置图例标记的高度
  314. textStyle: {
  315. fontSize: 12,
  316. },
  317. data: ['商城', '公众号', '小红书']
  318. },
  319. xAxis: {
  320. type: 'category',
  321. data: data.xAxis
  322. },
  323. yAxis: {
  324. type: 'value',
  325. },
  326. series: [
  327. {
  328. name: '搜索引擎',
  329. type: 'line',
  330. data: data.yAxis.search,
  331. label: {
  332. show: true,
  333. formatter(param) {
  334. // correct the percentage
  335. return param.value + '%'
  336. }
  337. }
  338. },
  339. {
  340. name: '微信平台',
  341. type: 'line',
  342. data: data.yAxis.general,
  343. label: {
  344. show: true,
  345. formatter(param) {
  346. // correct the percentage
  347. return param.value + '%'
  348. }
  349. }
  350. },
  351. {
  352. name: '微博',
  353. type: 'line',
  354. data: data.yAxis.redBook,
  355. label: {
  356. show: true,
  357. formatter(param) {
  358. // correct the percentage
  359. return param.value + '%'
  360. }
  361. }
  362. },
  363. {
  364. name: '直接访问',
  365. type: 'line',
  366. data: data.yAxis.mall,
  367. label: {
  368. show: true,
  369. formatter(param) {
  370. // correct the percentage
  371. return param.value + '%'
  372. }
  373. }
  374. }
  375. ]
  376. };
  377. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  378. },
  379. // 采美站内访问量
  380. chartStationVisits(data,shopName){
  381. let myChart = echarts.init(document.getElementById('myChart5'))
  382. let option = {
  383. title: {
  384. text: `【${shopName}】品牌整体访问量`
  385. },
  386. tooltip: {
  387. trigger: 'axis',
  388. axisPointer: {
  389. type: 'shadow' //
  390. }
  391. },
  392. legend: {
  393. orient: 'horizontal',
  394. right: '0%',
  395. top:'0%',
  396. itemGap: 10, // 这里可以设置图例每项之间的间隔
  397. itemWidth: 20, // 这里可以设置图例标记的宽度
  398. itemHeight: 14, // 这里可以设置图例标记的高度
  399. textStyle: {
  400. fontSize: 12,
  401. },
  402. data: ['游客访问量', '机构访问量']
  403. },
  404. grid: {
  405. left: '3%',
  406. right: '4%',
  407. bottom: '3%',
  408. containLabel: true
  409. },
  410. xAxis: {
  411. type: 'category',
  412. data: data.xAxis
  413. },
  414. yAxis: {
  415. type: 'value',
  416. },
  417. series: [
  418. {
  419. name: '游客访问量',
  420. type: 'bar',
  421. stack: 'total',
  422. label: {
  423. show: false
  424. },
  425. emphasis: {
  426. focus: 'series'
  427. },
  428. barGap:'60%',
  429. barCategoryGap:'60%',
  430. data: data.yAxis.tourist
  431. },
  432. {
  433. name: '机构访问量',
  434. type: 'bar',
  435. stack: 'total',
  436. label: {
  437. show: false
  438. },
  439. emphasis: {
  440. focus: 'series'
  441. },
  442. barGap:'60%',
  443. barCategoryGap:'60%',
  444. data: data.yAxis.clubs
  445. }
  446. ]
  447. };
  448. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  449. },
  450. chartVisitTimes(data,shopName){ // 页面平均访问时长top5
  451. let myChart = echarts.init(document.getElementById('myChart6'))
  452. let option = {
  453. title: {
  454. text: `【${shopName}】访问页面平均时长top5(单位:秒)`,
  455. left: 'left'
  456. },
  457. tooltip: {
  458. trigger: 'axis',
  459. color:'#FE8645',
  460. formatter: function(params) { // 格式化 tooltip 内容
  461. return '访问时长:'+ params[0].value + 's'
  462. },
  463. axisPointer: {
  464. type: 'shadow'
  465. }
  466. },
  467. legend: {
  468. show:false,
  469. },
  470. grid: {
  471. left: '3%',
  472. right: '4%',
  473. bottom: '3%',
  474. containLabel: true
  475. },
  476. xAxis: {
  477. type: 'category',
  478. data: data.xAxis
  479. },
  480. yAxis: {
  481. type: 'value',
  482. splitLine:{
  483. show: true,
  484. lineStyle:{
  485. opacity:0.8,
  486. color:'#E1E1E1',
  487. type:'dashed'
  488. }
  489. },
  490. boundaryGap: [0, 0.01],
  491. axisLabel:{
  492. show: true,
  493. textStyle:{
  494. color: '#999999', //更改坐标轴文字颜色
  495. fontSize : 14, //更改坐标轴文字大小
  496. }
  497. },
  498. axisTick: {//轴网格,在xAxis或yAxis根下
  499. lineStyle:{
  500. width:1,
  501. color:'#E1E1E1',
  502. type:'dashed'
  503. }
  504. }
  505. },
  506. series: [
  507. {
  508. type: 'line',
  509. name: '访问时长',
  510. data: data.yAxis.series,
  511. color:'#4880FF',
  512. label: {
  513. show: true
  514. },
  515. areaStyle: {
  516. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  517. {
  518. offset: 0,
  519. color: 'rgb(72,128,255)'
  520. },
  521. {
  522. offset: 1,
  523. color: 'rgb(68,92,207)'
  524. }
  525. ])
  526. }
  527. }
  528. ]
  529. };
  530. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  531. },
  532. // 咨询用户月度分布
  533. chartLeadUserMonthly(data,shopName){
  534. let myChart = echarts.init(document.getElementById('myChart7'))
  535. let option = {
  536. title: {
  537. text: `【${shopName}】咨询用户月度分布(单位:个)`
  538. },
  539. tooltip: {
  540. trigger: 'axis',
  541. axisPointer: {
  542. type: 'shadow' //
  543. }
  544. },
  545. legend: {
  546. orient: 'horizontal',
  547. right: '0%',
  548. top:'0%',
  549. itemGap: 10, // 这里可以设置图例每项之间的间隔
  550. itemWidth: 20, // 这里可以设置图例标记的宽度
  551. itemHeight: 14, // 这里可以设置图例标记的高度
  552. textStyle: {
  553. fontSize: 12,
  554. },
  555. data: ['6月', '7月', '8月', '9月','10月']
  556. },
  557. grid: {
  558. left: '3%',
  559. right: '4%',
  560. bottom: '3%',
  561. containLabel: true
  562. },
  563. xAxis: {
  564. type: 'category',
  565. data: data.xAxis
  566. },
  567. yAxis: {
  568. type: 'value',
  569. },
  570. series: [
  571. {
  572. name: '咨询用户月度分布',
  573. type: 'bar',
  574. stack: 'total',
  575. label: {
  576. show: true
  577. },
  578. emphasis: {
  579. focus: 'series'
  580. },
  581. barGap:'60%',
  582. barCategoryGap:'60%',
  583. color:'#4880FF',
  584. data: data.yAxis.series
  585. }
  586. ]
  587. };
  588. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  589. },
  590. chartChannels(data,shopName){// 咨询用户地狱分布
  591. let myChart = echarts.init(document.getElementById('myChart8'))
  592. let option = {
  593. title: {
  594. text: `【${shopName}】咨询用户地域分布`
  595. },
  596. tooltip: {
  597. trigger: 'item'
  598. },
  599. visualMap: {
  600. min: 0,
  601. max: 1000,
  602. left: 'left',
  603. top: 'bottom',
  604. text: ['高', '低'], // 文本,默认为数值文本
  605. calculable: true,
  606. inRange: {
  607. color: ['#e0ffff', '#006edd']
  608. }
  609. },
  610. series: [
  611. {
  612. name: '中国',
  613. type: 'map',
  614. mapType: 'china', // 设置地图类型为中国省份地图
  615. roam: false, // 禁止缩放和平移操作
  616. label: {
  617. show: true // 显示省份标签
  618. },
  619. data: data.yAxis.series,
  620. itemStyle:{
  621. fontSize: 14,
  622. color:'#FE8645'
  623. }
  624. }
  625. ]
  626. };
  627. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  628. },
  629. chartUrbanize(data,shopName){ // 用户类型分布
  630. let myChart = echarts.init(document.getElementById('myChart9'))
  631. let option = {
  632. title: {
  633. text: `【${shopName}】访问用户类型分布`,
  634. left: 'left'
  635. },
  636. tooltip: {
  637. trigger: 'item'
  638. },
  639. legend: {
  640. orient: 'horizontal',
  641. top:'bottom'
  642. },
  643. series: [
  644. {
  645. name: '',
  646. color:['#45CCF8','#4880FF','#FE8645'],
  647. type: 'pie',
  648. radius: ['35%', '25%'],
  649. center: ['50%', '50%'],
  650. avoidLabelOverlap: false,
  651. label: {
  652. show: true,
  653. formatter(param) {
  654. // correct the percentage
  655. return param.name + ' (' + param.value + '%)';
  656. }
  657. },
  658. emphasis: {
  659. itemStyle: {
  660. shadowBlur: 10,
  661. shadowOffsetX: 0,
  662. shadowColor: 'rgba(0, 0, 0, 0.5)'
  663. }
  664. },
  665. data: data.series
  666. }
  667. ]
  668. };
  669. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  670. },
  671. chartUserIdentity(data,shopName){ // 用户身份分布
  672. let myChart = echarts.init(document.getElementById('myChart10'))
  673. let option = {
  674. title: {
  675. text: `【${shopName}】访问用户身份分布`,
  676. left: 'left'
  677. },
  678. tooltip: {
  679. trigger: 'item'
  680. },
  681. legend: {
  682. orient: 'horizontal',
  683. top:'bottom'
  684. },
  685. series: [
  686. {
  687. name: '',
  688. color:['#45CCF8','#4880FF','#1CC170'],
  689. type: 'pie',
  690. radius: ['35%', '25%'],
  691. center: ['50%', '50%'],
  692. avoidLabelOverlap: false,
  693. label: {
  694. show: true,
  695. formatter(param) {
  696. // correct the percentage
  697. return param.name + ' (' + param.value + '%)';
  698. }
  699. },
  700. emphasis: {
  701. itemStyle: {
  702. shadowBlur: 10,
  703. shadowOffsetX: 0,
  704. shadowColor: 'rgba(0, 0, 0, 0.5)'
  705. }
  706. },
  707. data: data.series
  708. }
  709. ]
  710. };
  711. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  712. },
  713. chartIntentions(data,shopName){ // 用户意向分布
  714. let myChart = echarts.init(document.getElementById('myChart11'))
  715. let option = {
  716. title: {
  717. text: `【${shopName}】用户意向分布`,
  718. left: 'left'
  719. },
  720. tooltip: {
  721. trigger: 'item'
  722. },
  723. legend: {
  724. orient: 'horizontal',
  725. top:'bottom'
  726. },
  727. series: [
  728. {
  729. name: '',
  730. color:['#45CCF8','#4880FF','#1CC170','#FF726E'],
  731. type: 'pie',
  732. radius: ['35%', '25%'],
  733. center: ['50%', '50%'],
  734. avoidLabelOverlap: false,
  735. label: {
  736. show: true,
  737. formatter(param) {
  738. // correct the percentage
  739. return param.name + ' (' + param.value + '%)';
  740. }
  741. },
  742. emphasis: {
  743. itemStyle: {
  744. shadowBlur: 10,
  745. shadowOffsetX: 0,
  746. shadowColor: 'rgba(0, 0, 0, 0.5)'
  747. }
  748. },
  749. data:data.series
  750. }
  751. ]
  752. };
  753. myChart.setOption(option); // 将选项应用到图表实例上,生成图表
  754. }
  755. },
  756. };
  757. }();