gameDetail.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. const chart = echarts.init(canvas, null, {
  85. width: width,
  86. height: height,
  87. devicePixelRatio: dpr // new
  88. });
  89. canvas.setChart(chart);
  90. var option = {
  91. legend: {
  92. show: false
  93. },
  94. grid: {
  95. x: 35,
  96. y: 40,
  97. x2: 10,
  98. y2: 35
  99. },
  100. tooltip: {
  101. show: true,
  102. trigger: 'axis'
  103. },
  104. xAxis: {
  105. type: 'category',
  106. data: xdata,
  107. axisLabel: {
  108. interval: 0,
  109. rotate: 40,
  110. color: '#999999'
  111. }
  112. },
  113. yAxis: {
  114. axisLine: {
  115. show: true
  116. },
  117. type: 'value',
  118. name: '收益曲线',
  119. },
  120. series: [{
  121. name: 'A',
  122. type: 'line',
  123. smooth: true,
  124. symbolSize: 8,
  125. lineStyle: {
  126. color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  127. offset: 0,
  128. color: '#FF2D68'
  129. }, {
  130. offset: 1,
  131. color: '#4C4BFF'
  132. }]),
  133. },
  134. itemStyle: {
  135. borderWidth: 5,
  136. borderColor: '#FFAD52',
  137. color: '#FFAD52'
  138. },
  139. data: ydata
  140. }]
  141. };
  142. chart.setOption(option);
  143. return chart;
  144. }
  145. })
  146. },
  147. })
  148. }