number.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. // pages/number/number.js
  2. import * as echarts from '../../ec-canvas/echarts';
  3. const app = getApp()
  4. var host = app.globalData.host;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. info:{},
  11. analyse:{},
  12. day:'',
  13. ec: {
  14. // onInit: initChart
  15. lazyLoad: true
  16. },
  17. page:0,
  18. casci:0,
  19. act:0
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. var y = new Date().getFullYear(), m = (new Date().getMonth() + 1), d = new Date().getDate();
  26. m = m > 9 ? m : '0' + m;
  27. d = d > 9 ? d : '0' + d;
  28. this.setData({
  29. day: y + '-' + m + '-' + d
  30. })
  31. // options.id=2;
  32. wx.showNavigationBarLoading()
  33. wx.request({
  34. url: host + '/api/casci/detail',
  35. method: 'GET',
  36. data: {
  37. id: options.id
  38. },
  39. success: res => {
  40. wx.hideNavigationBarLoading()
  41. if (res.data.code == 0) {
  42. this.setData({
  43. info:res.data.data
  44. })
  45. this.setChart()
  46. }
  47. }
  48. })
  49. wx.request({
  50. url: host + '/api/casci/analyse',
  51. method: 'GET',
  52. data: {
  53. id: options.id
  54. },
  55. success: res => {
  56. wx.hideNavigationBarLoading()
  57. if (res.data.code == 0) {
  58. this.setData({
  59. analyse: res.data.data
  60. })
  61. }
  62. }
  63. })
  64. },
  65. checkpage:function(e){
  66. this.setData({
  67. act: e.target.dataset.id
  68. })
  69. if (e.target.dataset.id == 0){
  70. this.setChart()
  71. }
  72. if (e.target.dataset.id == 1) {
  73. this.setChart1()
  74. this.setChart2()
  75. }
  76. },
  77. check:function(e){
  78. this.setData({
  79. casci:e.target.dataset.id
  80. })
  81. this.setChart()
  82. },
  83. checknum: function (e) {
  84. this.setData({
  85. page: e.target.dataset.id
  86. })
  87. this.setChart2()
  88. },
  89. setChart:function(){
  90. var records = [], xdata = [], ydata = [];
  91. if (this.data.casci == 0) {
  92. records = this.data.info.days7_casci;
  93. } else {
  94. records = this.data.info.days30_casci;
  95. }
  96. if (records.length <= 0) {
  97. return;
  98. }
  99. for (let i = 0; i < records.length; i++) {
  100. xdata.push(records[i].name)
  101. ydata.push(records[i].value)
  102. }
  103. this.oneComponent = this.selectComponent('#mychart');
  104. this.init_one(xdata, ydata)
  105. },
  106. setChart1: function () {
  107. console.log(2333)
  108. var records = [], xdata = [], ydata = [];
  109. records = this.data.analyse.days7_casci_zhuanfa;
  110. if (records.length <= 0) {
  111. return;
  112. }
  113. for (let i = 0; i < records.length; i++) {
  114. xdata.push(records[i].name)
  115. ydata.push(records[i].value)
  116. }
  117. this.oneComponent1 = this.selectComponent('#mychart1');
  118. this.init_two(xdata, ydata)
  119. },
  120. setChart2: function () {
  121. var records = [], xdata = [], ydata = [];
  122. if (this.data.page == 0) {
  123. records = this.data.info.days7_casci_read;
  124. } else if (this.data.page == 0) {
  125. records = this.data.info.days7_casci_zan;
  126. }else{
  127. records = this.data.info.days7_casci_zhuanfa;
  128. }
  129. records = this.data.analyse.days7_casci_zhuanfa;
  130. if (records.length <= 0) {
  131. return;
  132. }
  133. for (let i = 0; i < records.length; i++) {
  134. xdata.push(records[i].name)
  135. ydata.push(records[i].value)
  136. }
  137. this.oneComponent2 = this.selectComponent('#mychart2');
  138. this.init_three(xdata, ydata)
  139. },
  140. init_one: function (xdata, ydata) { //初始化第一个图表
  141. this.oneComponent.init((canvas, width, height, dpr) => {
  142. const chart = echarts.init(canvas, null, {
  143. width: width,
  144. height: height,
  145. devicePixelRatio: dpr
  146. });
  147. setOption(chart, xdata, ydata)
  148. this.chart = chart;
  149. return chart;
  150. });
  151. },
  152. init_two: function (xdata, ydata) { //初始化第一个图表
  153. this.oneComponent1.init((canvas, width, height, dpr) => {
  154. const chart = echarts.init(canvas, null, {
  155. width: width,
  156. height: height,
  157. devicePixelRatio: dpr
  158. });
  159. setOption(chart, xdata, ydata)
  160. this.chart = chart;
  161. return chart;
  162. });
  163. },
  164. init_three: function (xdata, ydata) { //初始化第一个图表
  165. this.oneComponent2.init((canvas, width, height, dpr) => {
  166. const chart = echarts.init(canvas, null, {
  167. width: width,
  168. height: height,
  169. devicePixelRatio: dpr
  170. });
  171. setOption(chart, xdata, ydata)
  172. this.chart = chart;
  173. return chart;
  174. });
  175. },
  176. /**
  177. * 生命周期函数--监听页面初次渲染完成
  178. */
  179. onReady: function () {
  180. },
  181. /**
  182. * 生命周期函数--监听页面显示
  183. */
  184. onShow: function () {
  185. },
  186. /**
  187. * 生命周期函数--监听页面隐藏
  188. */
  189. onHide: function () {
  190. },
  191. /**
  192. * 生命周期函数--监听页面卸载
  193. */
  194. onUnload: function () {
  195. },
  196. /**
  197. * 页面相关事件处理函数--监听用户下拉动作
  198. */
  199. onPullDownRefresh: function () {
  200. },
  201. /**
  202. * 页面上拉触底事件的处理函数
  203. */
  204. onReachBottom: function () {
  205. },
  206. /**
  207. * 用户点击右上角分享
  208. */
  209. onShareAppMessage: function () {
  210. }
  211. })
  212. function setOption(chart, xdata, ydata) {
  213. var option = {
  214. legend: {
  215. show: false
  216. },
  217. backgroundColor:'#F1F4F6',
  218. grid: {
  219. x: 50,
  220. y: 30,
  221. x2: 10,
  222. y2: 35
  223. },
  224. tooltip: {
  225. show: true,
  226. trigger: 'axis',
  227. formatter: '{b0}: {c0}'
  228. },
  229. xAxis: {
  230. type: 'category',
  231. data: xdata,
  232. axisLabel: {
  233. interval: 0,
  234. // rotate: 40,
  235. color: '#999999'
  236. }
  237. },
  238. yAxis: {
  239. axisLine: {
  240. show: true
  241. },
  242. type: 'value',
  243. name: '',
  244. axisLabel: {
  245. formatter: function (value, index) {//隐藏 0
  246. let texts = [];
  247. texts.push(value)
  248. return texts;
  249. },
  250. show: true
  251. },
  252. },
  253. series: [{
  254. name: 'A',
  255. type: 'line',
  256. smooth: true,
  257. symbolSize: 8,
  258. lineStyle: {
  259. color: '#FF9F2E'
  260. // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  261. // offset: 0,
  262. // color: '#FF2D68'
  263. // }, {
  264. // offset: 1,
  265. // color: '#4C4BFF'
  266. // }]),
  267. },
  268. areaStyle: {
  269. color: {
  270. //线性渐变
  271. type: 'linear',
  272. x:0,
  273. y:0,
  274. x2:0,
  275. y2:1,
  276. colorStops: [{
  277. offset: 0, color: 'rgba(255, 159, 46, .5)', // 0% 处的颜色
  278. }, {
  279. offset: 1, color: 'rgba(255, 159, 46, .2)', // 100% 处的颜色
  280. }],
  281. global: false, // 缺省为 false
  282. },
  283. },
  284. itemStyle: {
  285. borderWidth: 5,
  286. borderColor: '#FFAD52',
  287. color: '#FFAD52'
  288. },
  289. data: ydata
  290. }]
  291. };
  292. chart.setOption(option)
  293. }