test.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // pages/test/test.js
  2. import uCharts from '../../utils/u-charts.js';
  3. var uChartsInstance = {};
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. cWidth: 750,
  10. cHeight: 500
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad(options) {
  16. },
  17. /**
  18. * 生命周期函数--监听页面初次渲染完成
  19. */
  20. onReady() {
  21. //这里的第一个 750 对应 css .charts 的 width
  22. const cWidth = 750 / 750 * wx.getSystemInfoSync().windowWidth;
  23. //这里的 500 对应 css .charts 的 height
  24. const cHeight = 500 / 750 * wx.getSystemInfoSync().windowWidth;
  25. this.setData({ cWidth, cHeight });
  26. this.getServerData();
  27. },
  28. /**
  29. * 生命周期函数--监听页面显示
  30. */
  31. onShow() {
  32. },
  33. /**
  34. * 生命周期函数--监听页面隐藏
  35. */
  36. onHide() {
  37. },
  38. /**
  39. * 生命周期函数--监听页面卸载
  40. */
  41. onUnload() {
  42. },
  43. /**
  44. * 页面相关事件处理函数--监听用户下拉动作
  45. */
  46. onPullDownRefresh() {
  47. },
  48. /**
  49. * 页面上拉触底事件的处理函数
  50. */
  51. onReachBottom() {
  52. },
  53. /**
  54. * 用户点击右上角分享
  55. */
  56. onShareAppMessage() {
  57. },
  58. getServerData() {
  59. //模拟从服务器获取数据时的延时
  60. setTimeout(() => {
  61. //模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
  62. let res = {
  63. categories: ["原麦汁浓度","酒精度","级别","喜爱度","苦度值"],
  64. series: [
  65. {
  66. name: "当前",
  67. data: [90,110,165,195,187]
  68. },
  69. {
  70. name: "平均",
  71. data: [190,210,105,35,27]
  72. }
  73. ]
  74. };
  75. this.drawCharts('uxXiJSVkwzQtHtxxJadNKGaTRVZrgait', res);
  76. }, 500);
  77. },
  78. drawCharts(id,data){
  79. const ctx = wx.createCanvasContext(id, this);
  80. uChartsInstance[id] = new uCharts({
  81. type: "radar",
  82. context: ctx,
  83. width: this.data.cWidth,
  84. height: this.data.cHeight,
  85. categories: data.categories,
  86. series: data.series,
  87. animation: true,
  88. background: "#FFFFFF",
  89. color: ["#FFA100","#258AFB"],
  90. padding: [5,5,5,5],
  91. dataLabel: false,
  92. enableScroll: false,
  93. border: false,
  94. legend: {
  95. show: false,
  96. position: "right",
  97. lineHeight: 25
  98. },
  99. extra: {
  100. radar: {
  101. gridType: "radar",
  102. gridColor: "#EEEEEE",
  103. gridCount: 5,
  104. opacity: 0.2,
  105. max: 200,
  106. gridEval: 5,
  107. labelShow: true,
  108. border: true
  109. }
  110. }
  111. });
  112. },
  113. tap(e){
  114. uChartsInstance[e.target.id].touchLegend(e);
  115. uChartsInstance[e.target.id].showToolTip(e);
  116. }
  117. })