avg.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. // pages/avg/avg.js
  2. import * as echarts from '../../ec-canvas/echarts';
  3. const $api = require('../../utils/api.js').API;
  4. var records = []
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. tab:['全体选手','冠军组','千万组','百万组'],
  11. list:[],
  12. cur:0,
  13. match_name:'',
  14. ec: {
  15. onInit: null
  16. },
  17. datas:[],
  18. date:'',
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad(options) {
  24. let nlist = JSON.parse(decodeURIComponent(options.list))
  25. nlist.unshift(nlist[0])
  26. // nlist[0].name='全体选手'
  27. console.log(nlist)
  28. this.setData({
  29. cur:options.index,
  30. list:nlist,
  31. match_name:nlist[0].match_name,
  32. })
  33. if(options.index == 0){
  34. this.loadAvg()
  35. } else{
  36. this.loadGroupAvg()
  37. }
  38. },
  39. loadGroupAvg(){
  40. var group = this.data.list[this.data.cur]
  41. var param = {
  42. match_id:group.match_id,
  43. group_id:group.match_group,
  44. }
  45. $api.getAllDay(param).then(res => {
  46. // console.log(res.data.data.list)
  47. if(res.data.code == 0){
  48. records = res.data.data.list
  49. var data = records[0]
  50. var date = data.stock_date.substring(0,7)
  51. var days = [], w = new Date(date + '-01').getDay();
  52. for (let i = 0; i < w; i++) {
  53. days.push({
  54. day: '',
  55. income: ''
  56. })
  57. }
  58. for (let i = 0; i < records.length; i++) {
  59. days.push({
  60. day: i+1,
  61. income: records[i].today_income,
  62. })
  63. }
  64. this.setData({
  65. ec: {
  66. onInit: initChart
  67. },
  68. days: days,
  69. date:date,
  70. })
  71. }
  72. })
  73. },
  74. loadAvg(){
  75. var group = this.data.list[0]
  76. var param = {
  77. match_id:group.match_id,
  78. }
  79. $api.getAvg(param).then(res => {
  80. if(res.data.code == 0){
  81. records = res.data.data.list
  82. var data = records[0]
  83. var date = data.stock_date.substring(0,7)
  84. var days = [], w = new Date(date + '-01').getDay();
  85. for (let i = 0; i < w; i++) {
  86. days.push({
  87. day: '',
  88. income: ''
  89. })
  90. }
  91. for (let i = 0; i < records.length; i++) {
  92. days.push({
  93. day: i+1,
  94. income: records[i].today_income,
  95. })
  96. }
  97. this.setData({
  98. ec: {
  99. onInit: initChart
  100. },
  101. days: days,
  102. date:date,
  103. })
  104. }
  105. })
  106. },
  107. tabChange(e){
  108. this.setData({
  109. cur:e.target.dataset.id
  110. })
  111. this.setData({
  112. ec:null,
  113. days:[]
  114. })
  115. if(e.target.dataset.id == 0){
  116. this.loadAvg()
  117. } else{
  118. this.loadGroupAvg()
  119. }
  120. },
  121. /**
  122. * 生命周期函数--监听页面初次渲染完成
  123. */
  124. onReady() {
  125. },
  126. /**
  127. * 生命周期函数--监听页面显示
  128. */
  129. onShow() {
  130. },
  131. /**
  132. * 生命周期函数--监听页面隐藏
  133. */
  134. onHide() {
  135. },
  136. /**
  137. * 生命周期函数--监听页面卸载
  138. */
  139. onUnload() {
  140. },
  141. /**
  142. * 页面相关事件处理函数--监听用户下拉动作
  143. */
  144. onPullDownRefresh() {
  145. },
  146. /**
  147. * 页面上拉触底事件的处理函数
  148. */
  149. onReachBottom() {
  150. },
  151. /**
  152. * 用户点击右上角分享
  153. */
  154. onShareAppMessage() {
  155. }
  156. })
  157. /**折线图 */
  158. function initChart(canvas, width, height, dpr) {
  159. var xdata = [], ydata = [];
  160. for (let i = 0; i < records.length; i++) {
  161. let date = records[i].stock_date.split('-');
  162. xdata.push(date[1] + '/' + date[2])
  163. let y = records[i].total_income.replace('%', '')
  164. ydata.push(Number(y))
  165. }
  166. xdata = xdata.reverse()
  167. ydata = ydata.reverse()
  168. const chart = echarts.init(canvas, null, {
  169. width: width,
  170. height: height,
  171. devicePixelRatio: dpr // new
  172. });
  173. canvas.setChart(chart);
  174. var option = {
  175. legend: {
  176. show: false
  177. },
  178. grid: {
  179. x: 40,
  180. y: 10,
  181. x2: 10,
  182. y2: 35
  183. },
  184. tooltip: {
  185. show: true,
  186. trigger: 'axis',
  187. formatter: '{b0}: {c0}%',
  188. },
  189. xAxis: {
  190. type: 'category',
  191. data: xdata,
  192. axisLabel: {
  193. interval: 0,
  194. rotate: 40,
  195. color: '#999999',
  196. interval: 2
  197. }
  198. },
  199. yAxis: {
  200. axisLine: {
  201. show: true,
  202. },
  203. type: 'value',
  204. // name: '收益曲线',
  205. axisLabel: {
  206. color: '#999999',
  207. formatter: function (value, index) {//隐藏 0
  208. let texts = [];
  209. texts.push(value + '%')
  210. return texts;
  211. },
  212. show: true
  213. },
  214. },
  215. series: [{
  216. name: 'A',
  217. type: 'line',
  218. smooth: true,
  219. symbolSize: 4,
  220. lineStyle: {
  221. color: '#FF2D68'
  222. // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  223. // offset: 0,
  224. // color: '#FF2D68'
  225. // }, {
  226. // offset: 1,
  227. // color: '#4C4BFF'
  228. // }]),
  229. },
  230. itemStyle: {
  231. borderWidth: 5,
  232. borderColor: '#FFAD52',
  233. color: '#FFAD52'
  234. },
  235. data: ydata
  236. }]
  237. };
  238. chart.setOption(option);
  239. return chart;
  240. }