1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
import * as echarts from '../../ec-canvas/echarts';
var util=require('../../utils/util');
let{score,xdata,ydata,downcount,watercount}=getApp().globalData; //从app.js中接收到数据
const app = getApp().globalData;
Page({
// 页面的初始数据
data: {
ec1: {
lazyLoad:true //仪表
},
ec2: {
lazyLoad:true //柱状
},
ec3: {
lazyLoad:true //多柱状
},
time:"",
month:[], //月份
// xdata:["6:30", "6:45", "9:30","10:00", "13:30", "14:40", "15:50"], //小时
alldata:[
['product', '久坐次数', '喝水次数', '坐下时长(h)'], //历史记录
['3月1日', 3, 6, 7],
['3月2日', 6, 4, 8],
['3月3日', 5, 6, 4],
['3月4日', 4, 9, 3],
],
downCount:downcount,
waterCount:watercount,
},
/**
* 生命周期函数--监听页面加载
*/
//动态刷新
onLoad: function (options) {
//获取小时并传到xdata中
var that = this;
setInterval(function(){
that.setData({
// xdata: util.formatHour(new Date()), //获取小时并传到xdata中
month: util.formatMonth(new Date()), //获取月日并传到xdata中
time: util.formatTime((new Date())),
});
},1000);
//获取到数据后渲染到图表
setTimeout(()=>{
this.lazyComponent=this.selectComponent('#mychart-dom-bar2') //获取到组件
this.initone(xdata,ydata), //坐下时间
this.lazyComponent=this.selectComponent('#mychart-dom-bar1') //获取到组件
this.inittwo(score), //得分
this.lazyComponent=this.selectComponent('#mychart-dom-bar3') //获取到组件
this.initthree(this.data.alldata) //历史记录
} ,1000) //定时为1S
},
// 下拉刷新
onRefresh:function(){
//导航条加载动画
wx.showNavigationBarLoading()
//loading 提示框
wx.showLoading({
title: 'Loading...',
})
console.log("下拉刷新啦");
setTimeout(function () {
wx.hideLoading();
wx.hideNavigationBarLoading();
//停止下拉刷新
wx.stopPullDownRefresh();
}, 1500)
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh:function(){
this.onRefresh();
this.lazyComponent=this.selectComponent('#mychart-dom-bar2') //获取到组件
this.initone(xdata,ydata) //坐下时间
},
//坐下时间
initone(xdata,ydata){ //手动初始化
this.lazyComponent.init((canvas,width,height,dpr)=>{
let chart=echarts.init(canvas,null,{
width:width,
height:height,
devicePixelRatio:dpr
})
let option=getOption(xdata,ydata)
chart.setOption(option)
this.chart=chart //将图表实例绑定到this上,方便其他函数访问
return chart
})
},
// 得分
inittwo(Score){ //手动初始化
this.lazyComponent.init((canvas,width,height,dpr)=>{
let chart=echarts.init(canvas,null,{
width:width,
height:height,
devicePixelRatio:dpr
})
let option=OnitChart(Score)
chart.setOption(option)
this.chart=chart //将图表实例绑定到this上,方便其他函数访问
return chart
})
},
//历史记录
initthree(xydata){ //手动初始化
this.lazyComponent.init((canvas,width,height,dpr)=>{
let chart=echarts.init(canvas,null,{
width:width,
height:height,
devicePixelRatio:dpr
})
let option=MoreinitChart(xydata)
chart.setOption(option)
this.chart=chart //将图表实例绑定到this上,方便其他函数访问
return chart
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
//对应的wxml中的ec-canvas id
this.oneComponent = this.selectComponent('ec1');
this.oneComponent = this.selectComponent('ec2');
this.oneComponent = this.selectComponent('ec3');
},
/**
* 生命周期函数--监听页面显示
*/
// 异步加载数据
})
// 坐下时间
function getOption (xdata,ydata) {
return{
title: {
text: ''
},
xAxis: {
type: 'category',
data: xdata
},
yAxis: {
type: 'value'
},
series: [
{
data: ydata,
type: 'bar',
showBackground: true,
backgroundStyle: {
color: 'rgba(180, 180, 180, 0.2)'
}
}
]
}
}
//得分
function OnitChart(Score) {
return{
series: [
{
type: 'gauge',
startAngle: 180,
endAngle: 0,
min: 0,
max: 1,
splitNumber: 8,
axisLine: {
lineStyle: {
width: 6,
color: [
[0.25, '#FF6E76'],
[0.5, '#FDDD60'],
[0.75, '#58D9F9'],
[1, '#7CFFB2']
]
}
},
pointer: {
icon: 'path://M12.8,0.7l12,40.1H0.7L12.8,0.7z',
length: '12%',
width: 20,
offsetCenter: [0, '-60%'],
itemStyle: {
color: 'auto'
}
},
axisTick: {
length: 12,
lineStyle: {
color: 'auto',
width: 2
}
},
splitLine: {
length: 20,
lineStyle: {
color: 'auto',
width: 5
}
},
axisLabel: {
color: '#464646',
fontSize: 20,
distance: -60,
formatter: function (value) {
if (value === 0.875) {
return 'A';
} else if (value === 0.625) {
return 'B';
} else if (value === 0.375) {
return 'C';
} else if (value === 0.125) {
return 'D';
}
return '';
}
},
title: {
offsetCenter: [0, '-20%'],
fontSize: 10
},
detail: {
fontSize: 15,
offsetCenter: [0, '0%'],
valueAnimation: true,
formatter: function (value) {
return Math.round(value * 100) + '分';
},
color: 'auto'
},
data: [
{
value:Score,
name: '今日综合得分'
}
]
}
]
}
}
//历史记录
function MoreinitChart(xydata) {
return{
legend: {},
tooltip: {},
dataset: {
source: xydata,
},
xAxis: { type: 'category' },
yAxis: {},
// Declare several bar series, each will be mapped
// to a column of dataset.source by default.
series: [{ type: 'bar' }, { type: 'bar' }, { type: 'bar' }]
};
}
|