xingweitongji.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <view class="content">
  3. <view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" ref="chartId" :id="chartId" class="echarts"></view>
  4. <view style="display: flex;justify-content: space-between; position: absolute;bottom: 30rpx; width: 542rpx; margin-left: 135rpx;align-items: center;">
  5. <text style="font-size: 18rpx;font-family: Verdana, Verdana-Regular;font-weight: 400;text-align: right;color: #868da4;">0</text>
  6. <view style="border-top:1rpx solid rgba(200,202,210,1);width: 490rpx;"></view>
  7. <text style="font-size: 18rpx;font-family: Verdana, Verdana-Regular;font-weight: 400;text-align: right;color: #868da4;">100</text>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. import echarts from '../../static/echarts.js'
  13. export default {
  14. props: {
  15. chartId: String,
  16. title: {
  17. type: String,
  18. default: '总访客量'
  19. },
  20. rightTitle: {
  21. type: String,
  22. default: '占比'
  23. },
  24. dataList: {
  25. type: Array,
  26. default: () => {
  27. return []
  28. }
  29. }
  30. },
  31. data() {
  32. return {
  33. dateArray: [],
  34. data1: [],
  35. themeColor: "",
  36. themeColor25: "",
  37. option: {
  38. tooltip: {
  39. show:false
  40. },
  41. grid: {
  42. left: '3%',
  43. right: '15%',
  44. bottom: '3%',
  45. top: '3%',
  46. containLabel: true
  47. },
  48. xAxis: {
  49. type: 'value',
  50. show: false,
  51. dataMax:100,
  52. },
  53. yAxis: {
  54. type: 'category',
  55. data: [],
  56. axisLabel: {
  57. textStyle: {
  58. color: '#666666',
  59. fontStyle: 'normal',
  60. fontFamily: '微软雅黑',
  61. fontSize: 12,
  62. }
  63. },
  64. axisTick: {
  65. show: false
  66. },
  67. axisLine: { //坐标轴轴线相关设置
  68. show: false
  69. },
  70. },
  71. series: [{
  72. type: 'bar',
  73. data: [],
  74. barWidth: 12,
  75. itemStyle: {
  76. // color: '#56CBCB'
  77. normal:{
  78. label: {
  79. show: true, //开启显示
  80. position: 'right', //在上方显示
  81. textStyle: { //数值样式
  82. color: '#202638',
  83. fontSize: 14,
  84. family: 'Verdana'
  85. },
  86. backgroundColor:'#CEF6F6',
  87. padding: [5, 15, 3,15],
  88. borderRadius:5,
  89. verticalAlign: 'middle',
  90. },
  91. color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  92. offset: 0,
  93. color: "#3CD9D9"
  94. }, {
  95. offset: 1,
  96. color: '#CEF6F6'
  97. }]),
  98. },
  99. },
  100. }]
  101. }
  102. }
  103. },
  104. methods: {
  105. getDataAction() {
  106. // this.dataList = []
  107. // this.data1 = []
  108. // for (var i = 0; i < 6; i++) {
  109. // var num1 = Math.ceil(Math.random() * 50)
  110. // this.data1.push(num1)
  111. // this.dataList.push(num1)
  112. // }
  113. this.data1 = []
  114. this.dateArray = []
  115. this.option.series[0].data = this.data1
  116. this.option.yAxis.data = this.dateArray
  117. var self = this
  118. this.dataList.forEach((item, index) => {
  119. self.data1.push(item.count)
  120. self.dateArray.push(item.title)
  121. })
  122. this.option.series[0].data = this.data1
  123. this.option.yAxis.data = this.dateArray
  124. // console.log('行为统计数据刷新', this.option.series)
  125. },
  126. onViewClick(options) {
  127. // console.log(options)
  128. }
  129. },
  130. watch: {
  131. chartId: {
  132. handler(e) {
  133. // console.log('走没走!!!!', e)
  134. // this.getDataAction()
  135. },
  136. immediate: true
  137. },
  138. dataList: {
  139. handler(e) {
  140. this.getDataAction()
  141. },
  142. immediate: true,
  143. deep: true
  144. }
  145. },
  146. mounted() {
  147. let app = getApp()
  148. let globalData = app.globalData;
  149. this.themeColor = globalData.themeColor
  150. this.themeColor25 = globalData.themeColor25
  151. let that = this;
  152. this.option.series[0].itemStyle.normal.label.backgroundColor = that.themeColor25
  153. this.option.series[0].itemStyle.normal.color = new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  154. offset: 0,
  155. color: that.themeColor
  156. }, {
  157. offset: 1,
  158. color: that.themeColor25
  159. }])
  160. }
  161. }
  162. </script>
  163. <script module="echarts" lang="renderjs">
  164. let myChart
  165. export default {
  166. mounted() {
  167. this.initAction()
  168. },
  169. methods: {
  170. initAction() {
  171. if (typeof window.echarts === 'function') {
  172. this.initEcharts()
  173. } else {
  174. // 动态引入较大类库避免影响页面展示
  175. const script = document.createElement('script')
  176. // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
  177. script.src = 'static/echarts.js'
  178. script.onload = this.initEcharts.bind(this)
  179. document.head.appendChild(script)
  180. }
  181. },
  182. initEcharts() {
  183. // console.log("initEcharts -> this.$refs", this.$refs.chartId.$el.id)
  184. myChart = echarts.init(document.getElementById(this.$refs.chartId.$el.id))
  185. // 观测更新的数据在 view 层可以直接访问到
  186. if (myChart) {
  187. myChart.setOption(this.option)
  188. }
  189. },
  190. updateEcharts(newValue, oldValue, ownerInstance, instance) {
  191. // 监听 service 层数据变更
  192. if (myChart) {
  193. myChart.setOption(newValue)
  194. }
  195. },
  196. onClick(event, ownerInstance) {
  197. // 调用 service 层的方法
  198. ownerInstance.callMethod('onViewClick', {
  199. test: 'test'
  200. })
  201. }
  202. }
  203. }
  204. </script>
  205. <style scoped lang="scss">
  206. .content {
  207. width: 100%;
  208. height: 100%;
  209. position: relative;
  210. .top-Section {
  211. padding: 0 20rpx;
  212. display: flex;
  213. flex-direction: row;
  214. justify-content: space-between;
  215. font-family: Verdana;
  216. .title {
  217. font-size: 32rpx;
  218. font-weight: bold;
  219. color: #383838;
  220. }
  221. .rightBtn {
  222. font-size: 24rpx;
  223. color: #546074;
  224. margin-top: 5rpx;
  225. }
  226. }
  227. .echarts {
  228. width: 100%;
  229. margin-top: 0;
  230. height: 500rpx;
  231. }
  232. }
  233. </style>