list.js 9.9 KB

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