number.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // pages/number/number.js
  2. import * as echarts from '../../ec-canvas/echarts';
  3. const app = getApp()
  4. var host = app.globalData.host;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. info:{},
  11. day:'',
  12. ec: {
  13. // onInit: initChart
  14. lazyLoad: true
  15. },
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. var y = new Date().getFullYear(), m = (new Date().getMonth() + 1), d = new Date().getDate();
  22. m = m > 9 ? m : '0' + m;
  23. d = d > 9 ? d : '0' + d;
  24. this.setData({
  25. day: y + '-' + m + '-' + d
  26. })
  27. options.id=2;
  28. wx.showNavigationBarLoading()
  29. wx.request({
  30. url: host + '/api/casci/detail',
  31. method: 'GET',
  32. data: {
  33. id: options.id
  34. },
  35. success: res => {
  36. wx.hideNavigationBarLoading()
  37. if (res.data.code == 0) {
  38. this.setData({
  39. info:res.data.data
  40. })
  41. var records = res.data.data.days7_casci, xdata = [], ydata = [];
  42. if (records.length <= 0) {
  43. return;
  44. }
  45. for (let i = 0; i < records.length; i++) {
  46. xdata.push(records[i].name)
  47. ydata.push(records[i].value)
  48. xdata.push(records[i].name)
  49. ydata.push(2500)
  50. xdata.push(records[i].name)
  51. ydata.push(1800)
  52. }
  53. // xdata = xdata.reverse()
  54. // ydata = ydata.reverse()
  55. this.oneComponent = this.selectComponent('#mychart');
  56. this.init_one(xdata, ydata)
  57. }
  58. }
  59. })
  60. },
  61. init_one: function (xdata, ydata) { //初始化第一个图表
  62. this.oneComponent.init((canvas, width, height, dpr) => {
  63. const chart = echarts.init(canvas, null, {
  64. width: width,
  65. height: height,
  66. devicePixelRatio: dpr
  67. });
  68. setOption(chart, xdata, ydata)
  69. this.chart = chart;
  70. return chart;
  71. });
  72. },
  73. /**
  74. * 生命周期函数--监听页面初次渲染完成
  75. */
  76. onReady: function () {
  77. },
  78. /**
  79. * 生命周期函数--监听页面显示
  80. */
  81. onShow: function () {
  82. },
  83. /**
  84. * 生命周期函数--监听页面隐藏
  85. */
  86. onHide: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面卸载
  90. */
  91. onUnload: function () {
  92. },
  93. /**
  94. * 页面相关事件处理函数--监听用户下拉动作
  95. */
  96. onPullDownRefresh: function () {
  97. },
  98. /**
  99. * 页面上拉触底事件的处理函数
  100. */
  101. onReachBottom: function () {
  102. },
  103. /**
  104. * 用户点击右上角分享
  105. */
  106. onShareAppMessage: function () {
  107. }
  108. })
  109. function setOption(chart, xdata, ydata) {
  110. var option = {
  111. legend: {
  112. show: false
  113. },
  114. backgroundColor:'#F1F4F6',
  115. grid: {
  116. x: 50,
  117. y: 40,
  118. x2: 10,
  119. y2: 35
  120. },
  121. tooltip: {
  122. show: true,
  123. trigger: 'axis',
  124. formatter: '{b0}: {c0}'
  125. },
  126. xAxis: {
  127. type: 'category',
  128. data: xdata,
  129. axisLabel: {
  130. interval: 0,
  131. // rotate: 40,
  132. color: '#999999'
  133. }
  134. },
  135. yAxis: {
  136. axisLine: {
  137. show: true
  138. },
  139. type: 'value',
  140. name: '',
  141. axisLabel: {
  142. formatter: function (value, index) {//隐藏 0
  143. let texts = [];
  144. texts.push(value)
  145. return texts;
  146. },
  147. show: true
  148. },
  149. },
  150. series: [{
  151. name: 'A',
  152. type: 'line',
  153. smooth: true,
  154. symbolSize: 8,
  155. lineStyle: {
  156. color: '#FF9F2E'
  157. // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  158. // offset: 0,
  159. // color: '#FF2D68'
  160. // }, {
  161. // offset: 1,
  162. // color: '#4C4BFF'
  163. // }]),
  164. },
  165. areaStyle: {
  166. color: {
  167. //线性渐变
  168. type: 'linear',
  169. x:0,
  170. y:0,
  171. x2:0,
  172. y2:1,
  173. colorStops: [{
  174. offset: 0, color: 'rgba(255, 159, 46, .5)', // 0% 处的颜色
  175. }, {
  176. offset: 1, color: 'rgba(255, 159, 46, .2)', // 100% 处的颜色
  177. }],
  178. global: false, // 缺省为 false
  179. },
  180. },
  181. itemStyle: {
  182. borderWidth: 5,
  183. borderColor: '#FFAD52',
  184. color: '#FFAD52'
  185. },
  186. data: ydata
  187. }]
  188. };
  189. chart.setOption(option)
  190. }