number.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. analyse:{},
  12. day:'',
  13. ec: {
  14. // onInit: initChart
  15. lazyLoad: true
  16. },
  17. page:0,
  18. casci:0,
  19. act:0,
  20. list:[]
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. var y = new Date().getFullYear(), m = (new Date().getMonth() + 1), d = new Date().getDate();
  27. m = m > 9 ? m : '0' + m;
  28. d = d > 9 ? d : '0' + d;
  29. this.setData({
  30. day: y + '-' + m + '-' + d
  31. })
  32. // options.id=2;
  33. wx.showNavigationBarLoading()
  34. wx.request({
  35. url: host + '/api/casci/detail',
  36. method: 'GET',
  37. data: {
  38. id: options.id
  39. },
  40. success: res => {
  41. wx.hideNavigationBarLoading()
  42. if (res.data.code == 0) {
  43. this.setData({
  44. info:res.data.data
  45. })
  46. this.setChart()
  47. }
  48. }
  49. })
  50. wx.request({
  51. url: host + '/api/casci/analyse',
  52. method: 'GET',
  53. data: {
  54. id: options.id
  55. },
  56. success: res => {
  57. wx.hideNavigationBarLoading()
  58. if (res.data.code == 0) {
  59. this.setData({
  60. analyse: res.data.data
  61. })
  62. }
  63. }
  64. })
  65. this.getData(options.id)
  66. },
  67. getData: function (id) {
  68. wx.showNavigationBarLoading()
  69. const _list = this.data.list;
  70. var index = this.data.index;
  71. wx.request({
  72. url: host + '/api/article/list',
  73. method: 'GET',
  74. data: {
  75. journal_id:id,
  76. page_size:9999
  77. // order_by: this.data.val[index],
  78. // keyword: this.data.keyword,
  79. // page: this.data.page
  80. },
  81. success: res => {
  82. wx.hideNavigationBarLoading()
  83. if (res.data.code == 0) {
  84. const list = res.data.data.list;
  85. for (let i = 0; i < list.length; i++) {
  86. _list.push(list[i])
  87. }
  88. this.setData({
  89. list: _list,
  90. total: res.data.data.total
  91. })
  92. }
  93. }
  94. })
  95. },
  96. checkpage:function(e){
  97. this.setData({
  98. act: e.target.dataset.id
  99. })
  100. if (e.target.dataset.id == 0){
  101. this.setChart()
  102. }
  103. if (e.target.dataset.id == 1) {
  104. this.setChart1()
  105. this.setChart2()
  106. }
  107. },
  108. check:function(e){
  109. this.setData({
  110. casci:e.target.dataset.id
  111. })
  112. this.setChart()
  113. },
  114. checknum: function (e) {
  115. this.setData({
  116. page: e.target.dataset.id
  117. })
  118. this.setChart2()
  119. },
  120. setChart:function(){
  121. var records = [], xdata = [], ydata = [];
  122. if (this.data.casci == 0) {
  123. records = this.data.info.days7_casci;
  124. } else {
  125. records = this.data.info.days30_casci;
  126. }
  127. if (records.length <= 0) {
  128. return;
  129. }
  130. for (let i = 0; i < records.length; i++) {
  131. xdata.push(records[i].name)
  132. ydata.push(records[i].value)
  133. }
  134. this.oneComponent = this.selectComponent('#mychart');
  135. this.init_one(xdata, ydata)
  136. },
  137. setChart1: function () {
  138. console.log(2333)
  139. var records = [], xdata = [], ydata = [];
  140. records = this.data.analyse.days7_casci_zhuanfa;
  141. if (records.length <= 0) {
  142. return;
  143. }
  144. for (let i = 0; i < records.length; i++) {
  145. xdata.push(records[i].name)
  146. ydata.push(records[i].value)
  147. }
  148. this.oneComponent1 = this.selectComponent('#mychart1');
  149. this.init_two(xdata, ydata)
  150. },
  151. setChart2: function () {
  152. var records = [], xdata = [], ydata = [];
  153. if (this.data.page == 0) {
  154. records = this.data.info.days7_casci_read;
  155. } else if (this.data.page == 0) {
  156. records = this.data.info.days7_casci_zan;
  157. }else{
  158. records = this.data.info.days7_casci_zhuanfa;
  159. }
  160. records = this.data.analyse.days7_casci_zhuanfa;
  161. if (records.length <= 0) {
  162. return;
  163. }
  164. for (let i = 0; i < records.length; i++) {
  165. xdata.push(records[i].name)
  166. ydata.push(records[i].value)
  167. }
  168. this.oneComponent2 = this.selectComponent('#mychart2');
  169. this.init_three(xdata, ydata)
  170. },
  171. init_one: function (xdata, ydata) { //初始化第一个图表
  172. this.oneComponent.init((canvas, width, height, dpr) => {
  173. const chart = echarts.init(canvas, null, {
  174. width: width,
  175. height: height,
  176. devicePixelRatio: dpr
  177. });
  178. setOption(chart, xdata, ydata)
  179. this.chart = chart;
  180. return chart;
  181. });
  182. },
  183. init_two: function (xdata, ydata) { //初始化第一个图表
  184. this.oneComponent1.init((canvas, width, height, dpr) => {
  185. const chart = echarts.init(canvas, null, {
  186. width: width,
  187. height: height,
  188. devicePixelRatio: dpr
  189. });
  190. setOption(chart, xdata, ydata)
  191. this.chart = chart;
  192. return chart;
  193. });
  194. },
  195. init_three: function (xdata, ydata) { //初始化第一个图表
  196. this.oneComponent2.init((canvas, width, height, dpr) => {
  197. const chart = echarts.init(canvas, null, {
  198. width: width,
  199. height: height,
  200. devicePixelRatio: dpr
  201. });
  202. setOption(chart, xdata, ydata)
  203. this.chart = chart;
  204. return chart;
  205. });
  206. },
  207. /**
  208. * 生命周期函数--监听页面初次渲染完成
  209. */
  210. onReady: function () {
  211. },
  212. /**
  213. * 生命周期函数--监听页面显示
  214. */
  215. onShow: function () {
  216. },
  217. /**
  218. * 生命周期函数--监听页面隐藏
  219. */
  220. onHide: function () {
  221. },
  222. /**
  223. * 生命周期函数--监听页面卸载
  224. */
  225. onUnload: function () {
  226. },
  227. /**
  228. * 页面相关事件处理函数--监听用户下拉动作
  229. */
  230. onPullDownRefresh: function () {
  231. },
  232. /**
  233. * 页面上拉触底事件的处理函数
  234. */
  235. onReachBottom: function () {
  236. },
  237. /**
  238. * 用户点击右上角分享
  239. */
  240. onShareAppMessage: function () {
  241. }
  242. })
  243. function setOption(chart, xdata, ydata) {
  244. var option = {
  245. legend: {
  246. show: false
  247. },
  248. backgroundColor:'#F1F4F6',
  249. grid: {
  250. x: 50,
  251. y: 30,
  252. x2: 10,
  253. y2: 35
  254. },
  255. tooltip: {
  256. show: true,
  257. trigger: 'axis',
  258. formatter: '{b0}: {c0}'
  259. },
  260. xAxis: {
  261. type: 'category',
  262. data: xdata,
  263. axisLabel: {
  264. interval: 0,
  265. // rotate: 40,
  266. color: '#999999'
  267. }
  268. },
  269. yAxis: {
  270. axisLine: {
  271. show: true
  272. },
  273. type: 'value',
  274. name: '',
  275. axisLabel: {
  276. formatter: function (value, index) {//隐藏 0
  277. let texts = [];
  278. texts.push(value)
  279. return texts;
  280. },
  281. show: true
  282. },
  283. },
  284. series: [{
  285. name: 'A',
  286. type: 'line',
  287. smooth: true,
  288. symbolSize: 8,
  289. lineStyle: {
  290. color: '#FF9F2E'
  291. // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  292. // offset: 0,
  293. // color: '#FF2D68'
  294. // }, {
  295. // offset: 1,
  296. // color: '#4C4BFF'
  297. // }]),
  298. },
  299. areaStyle: {
  300. color: {
  301. //线性渐变
  302. type: 'linear',
  303. x:0,
  304. y:0,
  305. x2:0,
  306. y2:1,
  307. colorStops: [{
  308. offset: 0, color: 'rgba(255, 159, 46, .5)', // 0% 处的颜色
  309. }, {
  310. offset: 1, color: 'rgba(255, 159, 46, .2)', // 100% 处的颜色
  311. }],
  312. global: false, // 缺省为 false
  313. },
  314. },
  315. itemStyle: {
  316. borderWidth: 5,
  317. borderColor: '#FFAD52',
  318. color: '#FFAD52'
  319. },
  320. data: ydata
  321. }]
  322. };
  323. chart.setOption(option)
  324. }