details.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. // pages/details/details.js
  2. import * as echarts from '../../ec-canvas/echarts';
  3. var Chart=null;
  4. const app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. ec: {
  11. onInit: function (canvas, width, height) {
  12. chart = echarts.init(canvas, null, {
  13. width: width,
  14. height: height
  15. });
  16. canvas.setChart(chart);
  17. return chart;
  18. },
  19. lazyLoad: true // 延迟加载
  20. },
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. this.echartsComponnet = this.selectComponent('#mychart');
  27. //如果是第一次绘制
  28. if (!Chart) {
  29. this.init_echarts(); //初始化图表
  30. } else {
  31. this.setOption(Chart); //更新数据
  32. }
  33. },
  34. //初始化图表
  35. init_echarts: function () {
  36. this.echartsComponnet.init((canvas, width, height) => {
  37. // 初始化图表
  38. const Chart = echarts.init(canvas, null, {
  39. width: width,
  40. height: height
  41. });
  42. this.setOption(Chart)
  43. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  44. return Chart
  45. });
  46. },
  47. setOption: function (Chart) {
  48. Chart.clear(); // 清除
  49. Chart.setOption(this.getOption()); //获取新数据
  50. },
  51. // 图表配置项
  52. getOption() {
  53. var self = this;
  54. var option = {
  55. title: {//标题
  56. text: '',
  57. left: 'center'
  58. },
  59. renderAsImage: true, //支持渲染为图片模式
  60. color: ["#DF3E3E", "#1AFA29"],//图例图标颜色
  61. legend: {
  62. show: true,
  63. itemGap: 25,//每个图例间的间隔
  64. top: 30,
  65. x: 30,//水平安放位置,离容器左侧的距离 'left'
  66. z: 100,
  67. textStyle: {
  68. color: '#383838'
  69. },
  70. data: [//图例具体内容
  71. {
  72. name: '涨幅',
  73. textStyle: {
  74. fontSize: 13,
  75. color: 'white'
  76. },
  77. icon: 'roundRect'
  78. },
  79. {
  80. name: '跌幅',
  81. textStyle: {
  82. fontSize: 13,
  83. color: 'white'
  84. },
  85. icon: 'roundRect'
  86. }
  87. ]
  88. },
  89. grid: {//网格
  90. left: 30,
  91. top:100,
  92. containLabel: true,//grid 区域是否包含坐标轴的刻度标签
  93. },
  94. xAxis: {//横坐标
  95. type: 'category',
  96. name: '区间',//横坐标名称
  97. nameTextStyle: {//在name值存在下,设置name的样式
  98. color: 'white',
  99. fontStyle: 'normal'
  100. },
  101. nameLocation:'end',
  102. splitLine: {//坐标轴在 grid 区域中的分隔线。
  103. show: true,
  104. lineStyle: {
  105. type: 'dashed'
  106. }
  107. },
  108. boundaryGap: false,//1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上
  109. data: ['10', '11', '12', '13', '14', '15', '16'],
  110. axisLabel: {
  111. textStyle: {
  112. fontSize: 13,
  113. color: '#5D5D5D'
  114. }
  115. }
  116. },
  117. yAxis: {//纵坐标
  118. type: 'value',
  119. position:'right',
  120. name: '股票值',//纵坐标名称
  121. nameTextStyle:{//在name值存在下,设置name的样式
  122. color:'red',
  123. fontStyle:'normal'
  124. },
  125. splitNumber: 5,//坐标轴的分割段数
  126. splitLine: {//坐标轴在 grid 区域中的分隔线。
  127. show: true,
  128. lineStyle: {
  129. type: 'dashed'
  130. }
  131. },
  132. axisLabel: {//坐标轴刻度标签
  133. formatter: function (value) {
  134. var xLable = [];
  135. if (value == 20) {
  136. xLable.push('25,883');
  137. }
  138. if (value == 40) {
  139. xLable.push('26,035');
  140. }
  141. if (value == 60) {
  142. xLable.push('26,187');
  143. }
  144. if (value == 80) {
  145. xLable.push('26,339');
  146. }
  147. return xLable
  148. },
  149. textStyle: {
  150. fontSize: 13,
  151. color: '#5D5D5D',
  152. }
  153. },
  154. min: 0,
  155. max: 100,
  156. },
  157. series: [{
  158. name: '涨幅',
  159. type: 'line',
  160. smooth:true,
  161. data: [18, 36, 65, 30, 78, 40, 33],
  162. symbol: 'none',
  163. itemStyle: {
  164. normal: {
  165. lineStyle: {
  166. color: '#DF3E3E'
  167. }
  168. }
  169. }
  170. }, {
  171. name: '跌幅',
  172. type: 'line',
  173. data: [10, 30, 31, 50, 40, 20, 10],
  174. symbol: 'none',
  175. itemStyle: {
  176. normal: {
  177. lineStyle: {
  178. color: '#1AFA29'
  179. }
  180. }
  181. }
  182. }],
  183. }
  184. return option;
  185. },
  186. /**
  187. * 生命周期函数--监听页面初次渲染完成
  188. */
  189. onReady: function () {
  190. },
  191. /**
  192. * 生命周期函数--监听页面显示
  193. */
  194. onShow: function () {
  195. },
  196. /**
  197. * 生命周期函数--监听页面隐藏
  198. */
  199. onHide: function () {
  200. },
  201. /**
  202. * 生命周期函数--监听页面卸载
  203. */
  204. onUnload: function () {
  205. },
  206. /**
  207. * 页面相关事件处理函数--监听用户下拉动作
  208. */
  209. onPullDownRefresh: function () {
  210. },
  211. /**
  212. * 页面上拉触底事件的处理函数
  213. */
  214. onReachBottom: function () {
  215. },
  216. /**
  217. * 用户点击右上角分享
  218. */
  219. onShareAppMessage: function () {
  220. },
  221. gotoNext:function(options){
  222. wx.navigateTo({
  223. url: '../next/next',
  224. })
  225. },
  226. backBtn:function(){
  227. wx.navigateBack();
  228. },
  229. })