gameDetail.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import * as echarts from '../../ec-canvas/echarts';
  2. const app = getApp();
  3. var host = app.globalData.host;
  4. var id;
  5. Page({
  6. onShareAppMessage: function (res) {
  7. return {
  8. title: 'ECharts 可以在微信小程序中使用啦!',
  9. path: '/pages/index/index',
  10. success: function () { },
  11. fail: function () { }
  12. }
  13. },
  14. data: {
  15. ec: {
  16. onInit: initChart
  17. }
  18. },
  19. onLoad(options) {
  20. id=options.id
  21. this.setData({
  22. id:id
  23. })
  24. wx.showNavigationBarLoading()
  25. /**获取token */
  26. wx.getStorage({
  27. key: 'userInfo',
  28. success: res => {
  29. this.setData({
  30. userInfo: res.data
  31. })
  32. this.getData(options.id);
  33. },
  34. fail: error => {
  35. //跳转到登陆页面
  36. wx.switchTab({
  37. url: '../user/user',
  38. })
  39. }
  40. })
  41. },
  42. getData(id) {
  43. wx.request({
  44. url: host + '/api/wx/player/match',
  45. data: { id: id },
  46. header: {
  47. 'Authorization': this.data.userInfo.token
  48. },
  49. success: res => {
  50. console.log(res)
  51. this.setData({
  52. datas: res.data.data
  53. })
  54. wx.hideNavigationBarLoading()
  55. },
  56. fail: error => {
  57. //跳转到登陆页面
  58. wx.switchTab({
  59. url: '../user/user',
  60. })
  61. }
  62. })
  63. },
  64. });
  65. /**折线图 */
  66. function initChart(canvas, width, height, dpr) {
  67. wx.getStorage({
  68. key: 'userInfo',
  69. success: res => {
  70. var info = res.data
  71. wx.request({
  72. url: host + '/api/wx/player/match',
  73. data:{id:id},
  74. header: {
  75. 'Authorization': info.token
  76. },
  77. success: res => {
  78. var records = res.data.data.records, xdata = [], ydata = [];
  79. for (let i = 0; i < records.length; i++) {
  80. let date = records[i].stock_date.split('-');
  81. xdata.push(date[1] + '/' + date[2])
  82. ydata.push(records[i].today_fund)
  83. }
  84. xdata = xdata.reverse()
  85. ydata = ydata.reverse()
  86. const chart = echarts.init(canvas, null, {
  87. width: width,
  88. height: height,
  89. devicePixelRatio: dpr // new
  90. });
  91. canvas.setChart(chart);
  92. var option = {
  93. legend: {
  94. show: false
  95. },
  96. grid: {
  97. x: 35,
  98. y: 40,
  99. x2: 10,
  100. y2: 35
  101. },
  102. tooltip: {
  103. show: true,
  104. trigger: 'axis'
  105. },
  106. xAxis: {
  107. type: 'category',
  108. data: xdata,
  109. axisLabel: {
  110. interval: 0,
  111. rotate: 40,
  112. color: '#999999'
  113. }
  114. },
  115. yAxis: {
  116. axisLine: {
  117. show: true
  118. },
  119. type: 'value',
  120. name: '收益曲线',
  121. },
  122. series: [{
  123. name: 'A',
  124. type: 'line',
  125. smooth: true,
  126. symbolSize: 8,
  127. lineStyle: {
  128. color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  129. offset: 0,
  130. color: '#FF2D68'
  131. }, {
  132. offset: 1,
  133. color: '#4C4BFF'
  134. }]),
  135. },
  136. itemStyle: {
  137. borderWidth: 5,
  138. borderColor: '#FFAD52',
  139. color: '#FFAD52'
  140. },
  141. data: ydata
  142. }]
  143. };
  144. chart.setOption(option);
  145. return chart;
  146. }
  147. })
  148. },
  149. })
  150. }