study.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. const app = getApp()
  2. import * as echarts from '../../../commpents/ec-canvas/echarts'
  3. Page({
  4. data: {
  5. frameStyle: { useTop: true, name: '学校学习情况', leftArrow: true, useBar: false },
  6. },
  7. // 返回
  8. back(e) {
  9. wx.navigateBack({ delta: 1 })
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: function (options) {
  15. },
  16. // 监听用户是否登录
  17. watchLogin: async function () {
  18. const that = this;
  19. wx.getStorage({
  20. key: 'user',
  21. success: async res => {
  22. that.setData({
  23. ec: {
  24. onInit: that.initChart
  25. }
  26. })
  27. // 模拟请求
  28. var times = setTimeout(async function () {
  29. that.data.data1 = [230, 150, 178, 70, 178, 340, 133, 118, 136, 165, 130, 178];
  30. that.data.data2 = [112, 150, 151, 135, 170, 130, 200, 112, 150, 151, 135, 170];
  31. clearTimeout(times);
  32. }, 1000)
  33. },
  34. fail: async res => {
  35. wx.redirectTo({ url: '/pages/index/index' })
  36. }
  37. })
  38. },
  39. // 折线图
  40. initChart(canvas, width, height, dpr) {
  41. let that = this;
  42. // 由于请求数据有延迟所以写一个时间函数,当数据存在的时候再执行绘制
  43. var times = setInterval(function () {
  44. var data1 = that.data.data1;
  45. var data2 = that.data.data2;
  46. if (data1 && data2) {
  47. clearInterval(times)
  48. const chart = echarts.init(canvas, null, {
  49. width: width,
  50. height: height,
  51. devicePixelRatio: dpr // new
  52. });
  53. canvas.setChart(chart);
  54. var option = {
  55. tooltip: {
  56. trigger: 'axis',
  57. axisPointer: {
  58. type: 'cross',
  59. label: {
  60. backgroundColor: '#6a7985'
  61. }
  62. }
  63. ,
  64. formatter: function (params) {
  65. let html = params[0].name + "<br>";
  66. for (let i = 0; i < params.length; i++) {
  67. html += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:' + params[i].color + ';"></span>'
  68. if (params[i].seriesName == "签到数") {
  69. html += params[i].seriesName + ":" + params[i].value + "%<br>";
  70. }
  71. if (params[i].seriesName == "时长") {
  72. html += params[i].seriesName + ":" + params[i].value + "小时<br>";
  73. }
  74. }
  75. return html;
  76. }
  77. },
  78. legend: {
  79. textStyle: { color: '#4CA6A3' },
  80. x: 'right',
  81. data: [{ name: '签到数', icon: 'rect' }, { name: '时长', icon: 'rect' }]
  82. },
  83. grid: {
  84. left: '2%',
  85. right: '2%',
  86. bottom: '3%',
  87. containLabel: true
  88. },
  89. xAxis: [
  90. {
  91. type: 'category',
  92. boundaryGap: false,
  93. // 设置x轴线的属性
  94. axisLabel: {
  95. //x轴文字的配置
  96. show: true,
  97. interval: 0,//使x轴文字显示全
  98. },
  99. axisLine: {
  100. lineStyle: {
  101. color: '#4CA6A3', // 设置x轴字体颜色
  102. width: 2, // 设置x轴字体宽度
  103. }
  104. },
  105. data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
  106. }
  107. ],
  108. yAxis: [
  109. {
  110. type: 'value',
  111. name: '时长',
  112. position: 'left',
  113. alignTicks: true,
  114. axisLine: {
  115. show: true,
  116. lineStyle: {
  117. fontSize: 16,
  118. color: '#293C55'
  119. }
  120. },
  121. axisLabel: {
  122. formatter: '{value} 小时'
  123. }
  124. },
  125. {
  126. type: 'value',
  127. alignTicks: true,
  128. nameGap: 10,
  129. nameRotate: 0,
  130. nameTextStyle: {
  131. fontSize: 16,
  132. color: '#293C55'
  133. },
  134. splitLine: { show: false },//去除网格线
  135. min: 0,
  136. max: 100,
  137. interval: 10,
  138. // 设置轴线的属性
  139. axisLine: {
  140. show: true,
  141. lineStyle: {
  142. color: '#293C55',
  143. }
  144. }
  145. }
  146. ],
  147. series: [
  148. {
  149. name: '签到数',
  150. type: 'line',
  151. stack: '总量',
  152. areaStyle: {},
  153. itemStyle: {
  154. normal: {
  155. color: "#25DEDB",//折线点的颜色
  156. lineStyle: {
  157. color: "#25DEDB"//折线的颜色
  158. }
  159. }
  160. },
  161. areaStyle: { // 该属性设置可以使这下图区域颜色达到渐变的效果
  162. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  163. offset: 0,
  164. color: '#25DEDB'
  165. }, {
  166. offset: 1,
  167. color: '#ffe'
  168. }])
  169. },
  170. data: data1
  171. },
  172. {
  173. name: '时长',
  174. type: 'line',
  175. stack: '总量',
  176. areaStyle: {},
  177. itemStyle: {
  178. normal: {
  179. color: "#E96C44",//折线点的颜色
  180. lineStyle: {
  181. color: "#E96C44"//折线的颜色
  182. }
  183. }
  184. },
  185. areaStyle: { // 该属性设置可以使这下图区域颜色达到渐变的效果
  186. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  187. offset: 0,
  188. color: '#E96C44'
  189. }, {
  190. offset: 1,
  191. color: '#ffe'
  192. }])
  193. },
  194. data: data2
  195. }
  196. ]
  197. };
  198. chart.setOption(option, true);
  199. return chart;
  200. }
  201. }, 100)
  202. },
  203. /**
  204. * 生命周期函数--监听页面初次渲染完成
  205. */
  206. onReady: function () { },
  207. /**
  208. * 生命周期函数--监听页面显示
  209. */
  210. onShow: function () {
  211. const that = this;
  212. // 监听用户是否登录
  213. that.watchLogin();
  214. },
  215. /**
  216. * 页面上拉触底事件的处理函数
  217. */
  218. /**
  219. * 生命周期函数--监听页面隐藏
  220. */
  221. onHide: function () {
  222. },
  223. /**
  224. * 生命周期函数--监听页面卸载
  225. */
  226. onUnload: function () {
  227. },
  228. /**
  229. * 页面相关事件处理函数--监听用户下拉动作
  230. */
  231. onPullDownRefresh: function () {
  232. },
  233. /**
  234. * 用户点击右上角分享
  235. */
  236. onShareAppMessage: function (res) {
  237. },
  238. })