item.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. // pages/item/item.js
  2. import * as echarts from '../../ec-canvas/echarts';
  3. var Api = require('../../utils/api.js');
  4. var wxRequest = require('../../utils/wxRequest.js')
  5. var timeData = [
  6. '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',
  7. ];
  8. timeData = timeData.map(function (str) {
  9. return str.replace('2009/', '');
  10. });
  11. var app = getApp()
  12. function initChart(canvas, width, height, dpr, data) {
  13. const chart = echarts.init(canvas, null, {
  14. width: width,
  15. height: height,
  16. devicePixelRatio: dpr // new
  17. });
  18. canvas.setChart(chart);
  19. var option = {
  20. title: {//标题
  21. text: '',
  22. left: 'center'
  23. },
  24. tooltip: {
  25. trigger: 'axis',
  26. axisPointer: {
  27. type: 'cross',
  28. label: {
  29. backgroundColor: '#6a7985'
  30. }
  31. }
  32. },
  33. renderAsImage: true, //支持渲染为图片模式
  34. color: ["#DF3E3E", "#80CDF8"],//图例图标颜色
  35. legend: {
  36. show: true,
  37. itemGap: 25,//每个图例间的间隔
  38. // top: 30,
  39. x: 30,//水平安放位置,离容器左侧的距离 'left'
  40. z: 100,
  41. textStyle: {
  42. color: '#383838'
  43. },
  44. },
  45. grid: {//网格
  46. // left: 30,
  47. // top:100,
  48. containLabel: true,//grid 区域是否包含坐标轴的刻度标签
  49. },
  50. xAxis: {//横坐标
  51. type: 'category',
  52. // nameTextStyle: {//在name值存在下,设置name的样式
  53. // color: 'white',
  54. // fontStyle: 'normal'
  55. // },
  56. nameLocation:'end',
  57. splitLine: {//坐标轴在 grid 区域中的分隔线。
  58. show: true,
  59. lineStyle: {
  60. type: 'dashed',
  61. color: ['#2B2B2B']
  62. }
  63. },
  64. boundaryGap: false,//1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上
  65. data: data.timeData,
  66. axisLine: {onZero: true},
  67. axisLabel: {
  68. textStyle: {
  69. fontSize: 13,
  70. color: '#5D5D5D'
  71. }
  72. }
  73. },
  74. dataZoom: [
  75. {
  76. type: 'slider',
  77. xAxisIndex: 0,
  78. filterMode: 'empty',
  79. start: 60,
  80. end: 100,
  81. handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
  82. handleSize: '80%',
  83. handleStyle: {
  84. color: '#fff',
  85. shadowBlur: 3,
  86. shadowColor: 'rgba(0, 0, 0, 0.6)',
  87. shadowOffsetX: 2,
  88. shadowOffsetY: 2
  89. }
  90. },
  91. {
  92. type: 'inside',
  93. realtime: true,
  94. }
  95. ],
  96. yAxis: {//纵坐标
  97. type: 'value',
  98. position:'right',
  99. // nameTextStyle:{//在name值存在下,设置name的样式
  100. // color:'red',
  101. // fontStyle:'normal'
  102. // },
  103. splitNumber: 5,//坐标轴的分割段数
  104. splitLine: {//坐标轴在 grid 区域中的分隔线。
  105. show: true,
  106. lineStyle: {
  107. type: 'dashed',
  108. color: ['#2B2B2B']
  109. }
  110. },
  111. axisLabel: {//坐标轴刻度标签
  112. // formatter: function (value) {
  113. // var xLable = [];
  114. // if (value == 20) {
  115. // xLable.push('25,883');
  116. // }
  117. // if (value == 40) {
  118. // xLable.push('26,035');
  119. // }
  120. // if (value == 60) {
  121. // xLable.push('26,187');
  122. // }
  123. // if (value == 80) {
  124. // xLable.push('26,339');
  125. // }
  126. // return xLable
  127. // },
  128. textStyle: {
  129. fontSize: 13,
  130. color: '#5D5D5D',
  131. }
  132. },
  133. // min: 0,
  134. // max: 100,
  135. },
  136. series: [{
  137. name: '实际',
  138. type: 'line',
  139. // smooth:true,
  140. data:data.actual,
  141. symbol: 'none',
  142. areaStyle: {
  143. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  144. offset: 0,
  145. color: data.color
  146. }, {
  147. offset: 1,
  148. color: '#1C1C1C'
  149. }])
  150. },
  151. itemStyle: {
  152. normal: {
  153. lineStyle: {
  154. color: data.color
  155. }
  156. }
  157. }
  158. }, {
  159. name: '预测',
  160. type: 'line',
  161. data: data.prediction,
  162. symbol: 'none',
  163. itemStyle: {
  164. normal: {
  165. lineStyle: {
  166. color: '#80CDF8'
  167. }
  168. }
  169. }
  170. }],
  171. };
  172. chart.setOption(option);
  173. return chart;
  174. }
  175. Page({
  176. /**
  177. * 页面的初始数据
  178. */
  179. data: {
  180. // 页面配置
  181. winWidth: 0,
  182. winHeight: 0,
  183. // tab切换
  184. currentTab: 0,
  185. button:"关注",
  186. ec: {
  187. onInit: initChart
  188. },
  189. realchartData:{
  190. actual:[552,586,3555,4454,552,556,4455],
  191. prediction:[552,546,3585,4424,542,546,35,44,524,56,355,444,2224,421],
  192. timeData : [
  193. '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',
  194. '2020/6/12','2020/6/13','2020/6/14',
  195. ],
  196. color:"crimson"
  197. },
  198. nextchartData:{
  199. actual:[572,556,3555,4744,552,576,3555],
  200. prediction:[352,246,385,2424,542,546,255],
  201. timeData : [
  202. '2020/6/1', '2020/6/2', '2020/6/3', '2020/6/4', '2020/6/5', '2020/6/6', '2020/6/7'
  203. ],
  204. color:"crimson"
  205. },
  206. object:{
  207. Name:"appl",
  208. value:"545455",
  209. color:'crimson',
  210. },
  211. newsData:[],
  212. },
  213. catchTouchMove:function(res){
  214. return false
  215. },
  216. // 滑动切换tab
  217. bindChange: function(e) {
  218. var that = this;
  219. that.setData({
  220. currentTab: e.detail.current
  221. });
  222. },
  223. //点击新闻
  224. onFold:function(e){
  225. console.log( e.currentTarget.dataset.id);
  226. wx.navigateTo({
  227. url:"../news/news"
  228. });
  229. },
  230. // 点击tab切换
  231. swichNav: function(e) {
  232. var that = this;
  233. if (this.data.currentTab === e.target.dataset.current) {
  234. return false;
  235. } else {
  236. that.setData({
  237. currentTab: e.target.dataset.current
  238. })
  239. }
  240. },
  241. /**
  242. * 生命周期函数--监听页面加载
  243. */
  244. onLoad: function (options) {
  245. console.log(JSON.parse(options.row))
  246. var Name = "object.Name"
  247. var value = "object.value"
  248. var color='object.color'
  249. let realcolor="realchartData.color",nextcolor="nextchartData.color", Values,colors
  250. if(JSON.parse(options.row).Tag){
  251. Values="+"+JSON.parse(options.row).Value.toFixed(2)+"%";
  252. colors="#D81E06";
  253. }else{
  254. Values="-"+JSON.parse(options.row).Value.toFixed(2)+"%"
  255. colors="#07c160"
  256. }
  257. this.setData({
  258. [Name]:JSON.parse(options.row).Name,
  259. [value]:Values,
  260. [color]:colors,
  261. [realcolor]:colors,
  262. [nextcolor]:colors,
  263. })
  264. var that = this;
  265. that.postbyiid(JSON.parse(options.row).IID,)
  266. that.postnewsbyiid(JSON.parse(options.row).IID)
  267. },
  268. //获取数据
  269. postbyiid:function(){
  270. var that = this;
  271. var postbyiid = wxRequest.postRequest(Api.postbyiid(),{'iid':'12'});
  272. postbyiid.then((res)=>{
  273. console.log(res)
  274. console.log(that.recursion(res.data))
  275. if(res.statusCode==200){
  276. that.setData({
  277. realchartData:that.recursion(res.data)
  278. })
  279. }
  280. })
  281. },
  282. recursion:function(row,a=[],b=[],c=[],d){
  283. for(let i in row.data){
  284. a.push(row.data[i].Date)
  285. b.push(row.data[i].Close)
  286. c.push(row.data[i].Pred)
  287. }
  288. if(row.tag){
  289. d="#D81E06"
  290. }else{
  291. d="#07c160"
  292. }
  293. return {"timeData":a,"actual":b,"prediction":c,"color":d}
  294. },
  295. //获取新闻
  296. postnewsbyiid:function(){
  297. var that = this;
  298. var postbyiid = wxRequest.postRequest(Api.postnewsbyiid(),{'iid':'12'});
  299. postbyiid.then((res)=>{
  300. console.log(res)
  301. // NID: "新闻id"
  302. // Title: "标题"
  303. // From: "来源"
  304. // MiniContent: "内容"
  305. // EID: ""
  306. // Date: "时间"
  307. // Tag: "情绪"
  308. console.log(that.recursion(res.data))
  309. if(res.statusCode==200){
  310. that.setData({
  311. newsData:res.data.data
  312. })
  313. }
  314. })
  315. },
  316. /**
  317. * 生命周期函数--监听页面初次渲染完成
  318. */
  319. onReady: function () {
  320. },
  321. /**
  322. * 生命周期函数--监听页面显示
  323. */
  324. onShow: function () {
  325. },
  326. /**
  327. * 生命周期函数--监听页面隐藏
  328. */
  329. onHide: function () {
  330. },
  331. /**
  332. * 生命周期函数--监听页面卸载
  333. */
  334. onUnload: function () {
  335. },
  336. /**
  337. * 页面相关事件处理函数--监听用户下拉动作
  338. */
  339. onPullDownRefresh: function () {
  340. },
  341. /**
  342. * 页面上拉触底事件的处理函数
  343. */
  344. onReachBottom: function () {
  345. },
  346. /**
  347. * 用户点击右上角分享
  348. */
  349. onShareAppMessage: function () {
  350. }
  351. })