Skip to content

Commit

Permalink
update the market page
Browse files Browse the repository at this point in the history
add function of updating price history data
  • Loading branch information
Cha0s0000 committed Apr 22, 2018
1 parent a1e951b commit 002ce64
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 17 deletions.
41 changes: 40 additions & 1 deletion pages/market/market.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Page({
/**
* The initial data of the page
*/
data: {
data: {

},

Expand Down Expand Up @@ -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
});
}
})
}
})
9 changes: 6 additions & 3 deletions pages/market/market.wxml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<!--pages/market/market.wxml-->
<view class="container">
<canvas canvas-id="priceHistory" disable-scroll="true" class="canvas" bindtouchstart="touchHandler"></canvas>
<button type="primary" bindtap="updateData">更新数据</button>
<view class="chart-container">
<view class="chart-title">
STEEM/SBD price history
</view>
<canvas canvas-id="priceHistory" disable-scroll="true" class="canvas" bindtouchstart="touchHandler"></canvas>
<button type="primary" bindtap="updateData">更新数据</button>
</view>
28 changes: 15 additions & 13 deletions pages/market/market.wxss
Original file line number Diff line number Diff line change
@@ -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;
}
width: 100%;
height: 200px;
}

0 comments on commit 002ce64

Please sign in to comment.