index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. //index.js
  2. //获取应用实例
  3. import * as echarts from '../../ec-canvas/echarts';
  4. var imageUtil = require('../../utils/window.js');
  5. var Chart=null;
  6. const app = getApp()
  7. var timeData = [
  8. '2020/6/1', '2009/6/2', '2009/6/3', '2009/6/4', '2009/6/5', '2009/6/6', '2009/6/7', '2009/6/8', '2009/6/9', '2009/6/10',
  9. ];
  10. timeData = timeData.map(function (str) {
  11. return str.replace('2009/', '');
  12. });
  13. function initChart(canvas, width, height, dpr, data) {
  14. const chart = echarts.init(canvas, null, {
  15. width: width,
  16. height: height,
  17. devicePixelRatio: dpr // new
  18. });
  19. canvas.setChart(chart);
  20. var option = {
  21. title: {//标题
  22. text: '',
  23. left: 'center'
  24. },
  25. renderAsImage: true, //支持渲染为图片模式
  26. color: ["#DF3E3E", "#80CDF8"],//图例图标颜色
  27. legend: {
  28. show: true,
  29. itemGap: 25,//每个图例间的间隔
  30. top: 30,
  31. x: 30,//水平安放位置,离容器左侧的距离 'left'
  32. z: 100,
  33. textStyle: {
  34. color: '#383838'
  35. },
  36. },
  37. grid: {//网格
  38. // left: 30,
  39. // top:100,
  40. containLabel: true,//grid 区域是否包含坐标轴的刻度标签
  41. },
  42. xAxis: {//横坐标
  43. type: 'category',
  44. // nameTextStyle: {//在name值存在下,设置name的样式
  45. // color: 'white',
  46. // fontStyle: 'normal'
  47. // },
  48. nameLocation:'end',
  49. splitLine: {//坐标轴在 grid 区域中的分隔线。
  50. show: true,
  51. lineStyle: {
  52. type: 'dashed',
  53. color: ['#2B2B2B']
  54. }
  55. },
  56. boundaryGap: false,//1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上
  57. data: data.timeData,
  58. axisLine: {onZero: true},
  59. axisLabel: {
  60. textStyle: {
  61. fontSize: 13,
  62. color: '#5D5D5D'
  63. }
  64. }
  65. },
  66. dataZoom: [
  67. {
  68. type: 'slider',
  69. xAxisIndex: 0,
  70. filterMode: 'empty'
  71. },
  72. ],
  73. yAxis: {//纵坐标
  74. type: 'value',
  75. position:'right',
  76. // nameTextStyle:{//在name值存在下,设置name的样式
  77. // color:'red',
  78. // fontStyle:'normal'
  79. // },
  80. splitNumber: 5,//坐标轴的分割段数
  81. splitLine: {//坐标轴在 grid 区域中的分隔线。
  82. show: true,
  83. lineStyle: {
  84. type: 'dashed',
  85. color: ['#2B2B2B']
  86. }
  87. },
  88. axisLabel: {//坐标轴刻度标签
  89. // formatter: function (value) {
  90. // var xLable = [];
  91. // if (value == 20) {
  92. // xLable.push('25,883');
  93. // }
  94. // if (value == 40) {
  95. // xLable.push('26,035');
  96. // }
  97. // if (value == 60) {
  98. // xLable.push('26,187');
  99. // }
  100. // if (value == 80) {
  101. // xLable.push('26,339');
  102. // }
  103. // return xLable
  104. // },
  105. textStyle: {
  106. fontSize: 13,
  107. color: '#5D5D5D',
  108. }
  109. },
  110. // min: 0,
  111. // max: 100,
  112. },
  113. series: [{
  114. name: '实际',
  115. type: 'line',
  116. // smooth:true,
  117. data:data.actual,
  118. symbol: 'none',
  119. areaStyle: {
  120. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  121. offset: 0,
  122. color: '#DF3E3E'
  123. }, {
  124. offset: 1,
  125. color: '#1C1C1C'
  126. }])
  127. },
  128. itemStyle: {
  129. normal: {
  130. lineStyle: {
  131. color: '#DF3E3E'
  132. }
  133. }
  134. }
  135. }, {
  136. name: '预测',
  137. type: 'line',
  138. data: data.prediction,
  139. symbol: 'none',
  140. itemStyle: {
  141. normal: {
  142. lineStyle: {
  143. color: '#80CDF8'
  144. }
  145. }
  146. }
  147. }],
  148. };
  149. chart.setOption(option);
  150. return chart;
  151. }
  152. Page({
  153. data: {
  154. url:'../../images/timg.jpg',
  155. motto: '',
  156. currentTab: 0,
  157. userInfo: {},
  158. hasUserInfo: false,
  159. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  160. imagewidth: 0,//缩放后的宽
  161. imageheight: 0,//缩放后的高
  162. chartData:{
  163. actual:[552,586,3555,4454,552,556,4455],
  164. prediction:[552,546,3585,4424,542,546,35,44,524,56,355,444,2224,421],
  165. timeData : [
  166. '2020/6/1', '2020/6/2', '2020/6/3', '2020/6/4', '2020/6/5', '2020/6/6', '2020/6/7', '2020/6/8', '2020/6/9', '2020/6/10','2020/6/11',
  167. '2020/6/12','2020/6/13','2020/6/14',
  168. ]
  169. },
  170. chartDatas:{
  171. actual:[572,556,3555,4744,552,576,3555],
  172. prediction:[352,246,385,2424,542,546,255],
  173. timeData : [
  174. '2020/6/1', '2020/6/2', '2020/6/3', '2020/6/4', '2020/6/5', '2020/6/6', '2020/6/7'
  175. ]
  176. },
  177. ec: {
  178. onInit: initChart
  179. },
  180. // ec: {
  181. // onInit: function (canvas, width, height) {
  182. // chart = echarts.init(canvas, null, {
  183. // width: width,
  184. // height: height
  185. // });
  186. // canvas.setChart(chart);
  187. // return chart;
  188. // },
  189. // lazyLoad: true // 延迟加载
  190. // },
  191. aa:[
  192. {
  193. id:'0',
  194. from:"Investing.com 中文",
  195. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  196. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  197. time:"6天前"
  198. },
  199. {
  200. id:'1',
  201. from:"chinese.aljazeera.net",
  202. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  203. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  204. time:"6天前"
  205. },
  206. {
  207. id:'2',
  208. from:"Investing.com 中文",
  209. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  210. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  211. time:"5天前"
  212. },
  213. {
  214. id:'3',
  215. from:"Investing.com 中文",
  216. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  217. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  218. time:"6天前"
  219. },
  220. {
  221. id:'4',
  222. from:"chinese.aljazeera.net",
  223. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  224. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  225. time:"6天前"
  226. },
  227. {
  228. id:'5',
  229. from:"Investing.com 中文",
  230. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  231. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  232. time:"5天前"
  233. },
  234. {
  235. id:'6',
  236. from:"Investing.com 中文",
  237. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  238. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  239. time:"6天前"
  240. },
  241. {
  242. id:'7',
  243. from:"chinese.aljazeera.net",
  244. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  245. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  246. time:"6天前"
  247. },
  248. {
  249. id:'8',
  250. from:"Investing.com 中文",
  251. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  252. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  253. time:"5天前"
  254. },
  255. {
  256. id:'9',
  257. from:"Investing.com 中文",
  258. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  259. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  260. time:"6天前"
  261. },
  262. {
  263. id:'10',
  264. from:"chinese.aljazeera.net",
  265. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  266. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  267. time:"6天前"
  268. },
  269. {
  270. id:'11',
  271. from:"Investing.com 中文",
  272. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  273. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  274. time:"5天前"
  275. },
  276. {
  277. id:'12',
  278. from:"Investing.com 中文",
  279. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  280. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  281. time:"6天前"
  282. },
  283. {
  284. id:'13',
  285. from:"chinese.aljazeera.net",
  286. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  287. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  288. time:"6天前"
  289. },
  290. {
  291. id:'14',
  292. from:"Investing.com 中文",
  293. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  294. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  295. time:"5天前"
  296. },
  297. ],
  298. },
  299. //事件处理函数
  300. bindViewTap: function() {
  301. wx.navigateTo({
  302. url: '../logs/logs'
  303. })
  304. },
  305. onReady: function (e) {
  306. this.computeScrollViewHeight();
  307. // var query = wx.createSelectorQuery()
  308. // query.select('#test').boundingClientRect(function (res) {
  309. // console.log(res.top);
  310. // }).exec();
  311. },
  312. onLoad: function () {
  313. let sysinfo = wx.getSystemInfoSync(),
  314. windowHeight = sysinfo.windowHeight,
  315. statusHeight = sysinfo.statusBarHeight,
  316. isiOS = sysinfo.system.indexOf('iOS') > -1,
  317. navHeight;
  318. if (!isiOS) {
  319. navHeight = 48;
  320. } else {
  321. navHeight = 44;
  322. }
  323. let height = windowHeight-statusHeight-navHeight;
  324. this.setData({
  325. height:height
  326. })
  327. // this.echartsComponnet = this.selectComponent('#mychart');
  328. // console.log(this.echartsComponnet);
  329. // //如果是第一次绘制
  330. // if (!Chart) {
  331. // this.init_echarts(); //初始化图表
  332. // } else {
  333. // this.setOption(Chart); //更新数据
  334. // }
  335. // this.computeScrollViewHeight();
  336. // if (app.globalData.userInfo) {
  337. // this.setData({
  338. // userInfo: app.globalData.userInfo,
  339. // hasUserInfo: true
  340. // })
  341. // } else if (this.data.canIUse){
  342. // // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  343. // // 所以此处加入 callback 以防止这种情况
  344. // app.userInfoReadyCallback = res => {
  345. // this.setData({
  346. // userInfo: res.userInfo,
  347. // hasUserInfo: true
  348. // })
  349. // }
  350. // } else {
  351. // // 在没有 open-type=getUserInfo 版本的兼容处理
  352. // wx.getUserInfo({
  353. // success: res => {
  354. // app.globalData.userInfo = res.userInfo
  355. // this.setData({
  356. // userInfo: res.userInfo,
  357. // hasUserInfo: true
  358. // })
  359. // }
  360. // })
  361. // }
  362. },
  363. computeScrollViewHeight() {
  364. var that = this
  365. let query = wx.createSelectorQuery().in(that)
  366. query.select('.swiper-tab').boundingClientRect()
  367. query.select('.chart').boundingClientRect()
  368. query.select('.news').boundingClientRect()
  369. query.exec(res => {
  370. let topHeight = res[0].height
  371. let searchHeight = res[1].height
  372. let titleHeight = res[2].height
  373. let windowHeight = wx.getSystemInfoSync().windowHeight
  374. let windowWidth = wx.getSystemInfoSync().windowWidth
  375. let height = windowHeight - topHeight - searchHeight - titleHeight
  376. let ratio = 750 / windowWidth
  377. let scrollHeight = height * ratio
  378. that.setData({ scrollHeight: scrollHeight})
  379. })
  380. },
  381. imageLoad: function (e) {
  382. var imageSize = imageUtil.imageUtil(e)
  383. this.setData({
  384. imagewidth: imageSize.imageWidth,
  385. imageheight: imageSize.imageHeight
  386. })
  387. this.computeScrollViewHeight();
  388. },
  389. onFold:function(e){
  390. console.log( e.currentTarget.dataset.id);
  391. wx.navigateTo({
  392. url:"../news/news"
  393. });
  394. },
  395. choose:function(e){
  396. wx.navigateTo({
  397. url:"../filter/filter"
  398. })
  399. },
  400. swichNav: function(e) {
  401. var that = this;
  402. if (this.data.currentTab === e.target.dataset.current) {
  403. return false;
  404. } else {
  405. that.setData({
  406. currentTab: e.target.dataset.current
  407. })
  408. }
  409. },
  410. // 滑动切换tab
  411. bindChange: function(e) {
  412. var that = this;
  413. that.setData({
  414. currentTab: e.detail.current
  415. });
  416. },
  417. catchTouchMove:function(res){
  418. return false
  419. },
  420. //初始化图表
  421. init_echarts: function () {
  422. this.echartsComponnet.init((canvas, width, height) => {
  423. // 初始化图表
  424. const Chart = echarts.init(canvas, null, {
  425. width: width,
  426. height: height
  427. });
  428. this.setOption(Chart)
  429. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  430. return Chart
  431. });
  432. },
  433. setOption: function (Chart) {
  434. Chart.clear(); // 清除
  435. Chart.setOption(this.getOption()); //获取新数据
  436. },
  437. // 图表配置项
  438. getOption() {
  439. var self = this;
  440. var option = {
  441. title: {//标题
  442. text: '',
  443. left: 'center'
  444. },
  445. renderAsImage: true, //支持渲染为图片模式
  446. color: ["#DF3E3E", "#80CDF8"],//图例图标颜色
  447. legend: {
  448. // left:'right',
  449. show: true,
  450. itemGap: 25,//每个图例间的间隔
  451. top: 20,
  452. right:20,
  453. x: 100,//水平安放位置,离容器左侧的距离 'left'
  454. z: 100,
  455. textStyle: {
  456. color: '#383838'
  457. },
  458. data: [//图例具体内容
  459. {
  460. name: '实际',
  461. textStyle: {
  462. fontSize: 13,
  463. color: 'white'
  464. },
  465. icon: 'line'
  466. },
  467. {
  468. name: '预测',
  469. textStyle: {
  470. fontSize: 13,
  471. color: 'white'
  472. },
  473. icon: 'line',
  474. }
  475. ]
  476. },
  477. grid: {//网格
  478. // left: 50,
  479. // top:100,
  480. containLabel: true,//grid 区域是否包含坐标轴的刻度标签
  481. },
  482. xAxis: {//横坐标
  483. type: 'category',
  484. // name: '区间',//横坐标名称
  485. nameTextStyle: {//在name值存在下,设置name的样式
  486. color: 'white',
  487. fontStyle: 'normal'
  488. },
  489. nameLocation:'end',
  490. splitLine: {//坐标轴在 grid 区域中的分隔线。
  491. show: true,
  492. lineStyle: {
  493. type: 'dashed',
  494. color: ['#2B2B2B']
  495. }
  496. },
  497. boundaryGap: false,//1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上
  498. data: ['2020/6/29', '2020/6/30', '2020/7/1', '2020/7/2', '2020/7/3'],
  499. axisLine: {onZero: true},
  500. axisLabel: {
  501. textStyle: {
  502. fontSize: 13,
  503. color: '#5D5D5D'
  504. }
  505. }
  506. },
  507. yAxis: {//纵坐标
  508. type: 'value',
  509. position:'right',
  510. name: '股票值',//纵坐标名称
  511. nameTextStyle:{//在name值存在下,设置name的样式
  512. color:'red',
  513. fontStyle:'normal'
  514. },
  515. splitNumber: 5,//坐标轴的分割段数
  516. splitLine: {//坐标轴在 grid 区域中的分隔线。
  517. show: true,
  518. lineStyle: {
  519. type: 'dashed',
  520. color: ['#2B2B2B']
  521. }
  522. },
  523. axisLabel: {//坐标轴刻度标签
  524. // formatter: function (value) {
  525. // var xLable = [];
  526. // if (value == 20) {
  527. // xLable.push('1000');
  528. // }
  529. // if (value == 40) {
  530. // xLable.push('2000');
  531. // }
  532. // if (value == 60) {
  533. // xLable.push('4000');
  534. // }
  535. // if (value == 80) {
  536. // xLable.push('6000');
  537. // }
  538. // return xLable
  539. // },
  540. textStyle: {
  541. fontSize: 13,
  542. color: '#5D5D5D',
  543. }
  544. },
  545. // min: 0,
  546. // max: 100,
  547. },
  548. series: [{
  549. name: '实际',
  550. type: 'line',
  551. // smooth:true,
  552. data: [1888, 3666, 6555, 3000, 7888, 4000, 3333],
  553. symbol: 'none',
  554. areaStyle: {
  555. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  556. {
  557. offset: 0,
  558. color: '#DF3E3E'
  559. },
  560. {
  561. offset: 1,
  562. color: '#1C1C1C'
  563. }
  564. ])
  565. },
  566. itemStyle: {
  567. normal: {
  568. lineStyle: {
  569. color: '#DF3E3E'
  570. }
  571. }
  572. }
  573. }, {
  574. name: '预测',
  575. type: 'line',
  576. data: [1000, 3000, 3111, 5000, 4000, 2000, 1000],
  577. symbol: 'none',
  578. itemStyle: {
  579. normal: {
  580. lineStyle: {
  581. color: '#80CDF8'
  582. }
  583. }
  584. }
  585. }],
  586. }
  587. return option;
  588. },
  589. getUserInfo: function(e) {
  590. console.log(e)
  591. app.globalData.userInfo = e.detail.userInfo
  592. this.setData({
  593. userInfo: e.detail.userInfo,
  594. hasUserInfo: true
  595. })
  596. }
  597. })