list.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. watchLogin: async function () {
  17. const that = this;
  18. wx.getStorage({
  19. key: 'user',
  20. success: async res => {
  21. that.setData({ ec: { onInit: that.initChart } })
  22. that.data.piedata = [
  23. { value: 55, name: '7-10岁' },
  24. { value: 20, name: '10-13岁' },
  25. { value: 10, name: '13-16岁' },
  26. { value: 20, name: '16-18岁' },
  27. { value: 38, name: '18-26岁' }];
  28. },
  29. fail: async res => {
  30. wx.redirectTo({ url: '/pages/index/index' })
  31. }
  32. })
  33. },
  34. // 折线图
  35. initChart(canvas, width, height, dpr) {
  36. let that = this;
  37. var piedata = that.data.piedata;
  38. const chart = echarts.init(canvas, null, {
  39. width: width,
  40. height: height,
  41. devicePixelRatio: dpr
  42. });
  43. canvas.setChart(chart);
  44. var option = {
  45. backgroundColor: "#ffffff",
  46. series: [{
  47. label: {
  48. normal: {
  49. fontSize: 14,
  50. }
  51. },
  52. type: 'pie',
  53. center: ['50%', '50%'],
  54. radius: ['20%', '40%'],
  55. data: piedata
  56. }],
  57. tooltip: {
  58. trigger: 'item',
  59. formatter: '{b}:{c}人' + '\n\r' + '({d}%)' // 格式化数值百分比输出
  60. },
  61. };
  62. chart.setOption(option, true);
  63. return chart;
  64. },
  65. /**
  66. * 生命周期函数--监听页面初次渲染完成
  67. */
  68. onReady: function () { },
  69. /**
  70. * 生命周期函数--监听页面显示
  71. */
  72. onShow: function () {
  73. const that = this;
  74. // 监听用户是否登录
  75. that.watchLogin();
  76. },
  77. /**
  78. * 页面上拉触底事件的处理函数
  79. */
  80. /**
  81. * 生命周期函数--监听页面隐藏
  82. */
  83. onHide: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面卸载
  87. */
  88. onUnload: function () {
  89. },
  90. /**
  91. * 页面相关事件处理函数--监听用户下拉动作
  92. */
  93. onPullDownRefresh: function () {
  94. },
  95. /**
  96. * 用户点击右上角分享
  97. */
  98. onShareAppMessage: function (res) {
  99. },
  100. })