From 002ce6419a611a12d8d08452934d60f05b24c6a7 Mon Sep 17 00:00:00 2001 From: Cha0s <457318796@qq.com> Date: Sun, 22 Apr 2018 12:59:13 +0800 Subject: [PATCH] update the market page add function of updating price history data --- pages/market/market.js | 41 +++++++++++++++++++++++++++++++++++++++- pages/market/market.wxml | 9 ++++++--- pages/market/market.wxss | 28 ++++++++++++++------------- 3 files changed, 61 insertions(+), 17 deletions(-) diff --git a/pages/market/market.js b/pages/market/market.js index c676119..b68fdfa 100644 --- a/pages/market/market.js +++ b/pages/market/market.js @@ -6,7 +6,7 @@ Page({ /** * The initial data of the page */ - data: { + data: { }, @@ -179,4 +179,43 @@ Page({ } }); }, + + updateData:function(e){ + var that = this; + var priceHistory = new Object(); + var priceMax = 1; + var priceMin = 0; + priceHistory.price = []; + priceHistory.time = []; + wx.request({ + url: 'https://min-api.cryptocompare.com/data/histoday?fsym=STEEM&tsym=SBD&limit=20', + method: 'GET', + success: function (res) { + if (res.statusCode == '200') { + var data = res.data.Data; + console.log(data); + for (var i in data) { + priceHistory.price.push(data[i].close); + priceHistory.time.push(that.getTime(data[i].time * 1000)); + } + console.log(priceHistory); + priceMax = Math.max.apply(null, priceHistory.price); + priceMin = Math.min.apply(null, priceHistory.price); + } + }, + complete:function(res){ + var updateSeries = [{ + name: 'STEEM/SBD', + data: priceHistory.price, + format: function (val, name) { + return val.toFixed(4); + } + }]; + lineChart.updateData({ + categories: priceHistory.time, + series: updateSeries + }); + } + }) + } }) \ No newline at end of file diff --git a/pages/market/market.wxml b/pages/market/market.wxml index 4c5eabf..3d9a928 100644 --- a/pages/market/market.wxml +++ b/pages/market/market.wxml @@ -1,5 +1,8 @@ - - - + + + STEEM/SBD price history + + + \ No newline at end of file diff --git a/pages/market/market.wxss b/pages/market/market.wxss index 85c976c..cf99200 100644 --- a/pages/market/market.wxss +++ b/pages/market/market.wxss @@ -1,16 +1,18 @@ /* pages/market/market.wxss */ -.container { - height: 100%; - display: flex; - flex-direction: column; - box-sizing: border-box; - -webkit-text-size-adjust:none; - -webkit-user-select: none; - font-size: 35rpx; - color: #333; - font-family: Helvetica,Arial,"Helvetica Neue","Droid Sans","Microsoft YaHei",sans-serif; +.chart-container { + height: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + padding: 50rpx 0; + box-sizing: border-box; +} +.chart-title{ + margin-bottom: 20rpx; + font-size:2ch } .canvas { - width: 100%; - height: 200px; -} \ No newline at end of file + width: 100%; + height: 200px; +}