This repository has been archived by the owner on Jul 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsteps.html
168 lines (163 loc) · 5.08 KB
/
steps.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="yes" name="apple-touch-fullscreen">
<meta content="telephone=no,email=no" name="format-detection">
<script src="https://gw.alipayobjects.com/os/antv/assets/f2/3.1.15/f2.min.js"></script>
<script src="https://gw.alipayobjects.com/os/antv/assets/lib/jquery-3.2.1.min.js"></script>
<title>运动</title>
<link rel="stylesheet" href="./css/steps.css" />
</head>
<body>
<div class="bkg">
<div class="avatar-container">
<a href="https://antv.alipay.com/zh-cn/f2/3.x/demo/index.html">
<img class="avatar" src="https://gw.alipayobjects.com/zos/rmsportal/bjtEqXVNIqVCgqhpdHmm.png" alt="antv" />
</a>
</div>
</div>
<div class="chart-container">
<div class="chart-header"></div>
<canvas id="mountNode"></canvas>
<!-- 自定义 tooltip -->
<div class="chart-tooltip" id="tooltip"></div>
</div>
<!-- js 脚本 -->
<script>
const data = [
{ date: '2018-04-21', steps: 59 },
{ date: '2018-04-22', steps: 2515 },
{ date: '2018-04-23', steps: 6524 },
{ date: '2018-04-24', steps: 26044 },
{ date: '2018-04-25', steps: 29763 },
{ date: '2018-04-26', steps: 10586 },
{ date: '2018-04-27', steps: 14758 },
{ date: '2018-04-29', steps: 549 },
{ date: '2018-04-30', steps: 21 },
{ date: '2018-05-01', steps: 1069 },
{ date: '2018-05-02', steps: 7918 },
{ date: '2018-05-03', steps: 5381 },
{ date: '2018-05-04', steps: 11549 },
{ date: '2018-05-06', steps: 19461 },
{ date: '2018-05-07', steps: 22487 },
{ date: '2018-05-08', steps: 11062 },
{ date: '2018-05-09', steps: 7101 },
{ date: '2018-05-10', steps: 12776 },
{ date: '2018-05-11', steps: 12919 },
{ date: '2018-05-12', steps: 7216 },
{ date: '2018-05-13', steps: 4867 },
{ date: '2018-05-14', steps: 8725 },
{ date: '2018-05-15', steps: 8983 },
{ date: '2018-05-16', steps: 22348 },
{ date: '2018-05-17', steps: 17142 },
{ date: '2018-05-18', steps: 8715 },
{ date: '2018-05-19', steps: 3861 },
{ date: '2018-05-20', steps: 8 },
{ date: '2018-05-21', steps: 24365 },
{ date: '2018-05-22', steps: 14271 }
];
$('.chart-header').text('步数:' + data[data.length - 1].steps);
// 创建区域图的渐变色
const canvas = document.getElementById('mountNode');
const ctx = canvas.getContext('2d');
const grd = ctx.createLinearGradient(0, canvas.offsetHeight, 0, 0);
grd.addColorStop(0.03, "rgba(216,216,216,0.10)");
grd.addColorStop(1, "#6E6CD8");
const chart = new F2.Chart({
id: 'mountNode',
pixelRatio: window.devicePixelRatio,
padding: [ 20, 30, 'auto', 'auto' ]
});
chart.source(data, {
date: {
type: 'timeCat',
range: [ 0, 1 ],
mask: 'MM-D'
},
steps: {
ticks: [ 10000 ],
formatter(val) {
return val === 10000 ? '1W' : 0;
}
}
});
chart.axis('date', {
line: {
stroke: '#85A5FF'
},
label(text, index, total) {
const cfg = {
textAlign: 'center',
fill: '#85A5FF',
fontSize: 12,
fontWeight: 300
};
if (index === 0) {
cfg.textAlign = 'start';
cfg.text = text.split('-').join('月');
} else {
cfg.text = text.split('-')[1];
}
if (index === total - 1) {
cfg.textAlign = 'end';
cfg.fill = '#ADC6FF';
cfg.fontWeight = 'normal';
}
return cfg;
}
});
chart.axis('steps', {
position: 'right',
label: {
fill: '#CFFFFE',
fillOpacity: 0.5,
fontSize: 9,
fontWeight: 300
},
grid: {
stroke: '#85A5FF'
}
});
chart.tooltip({
custom: true,
showCrosshairs: true,
showTooltipMarker: false,
crosshairsStyle: {
lineDash: [ 2 ],
stroke: '#77C0B3'
},
onChange(e) {
const item = e.items[0];
const origin = item.origin;
const tooltipEl = $('#tooltip');
tooltipEl.text(origin.steps);
// 设置 tooltip 位置
const canvasOffsetTop = $('#mountNode').position().top;
const canvasOffsetLeft = $('#mountNode').position().left;
const tooltipWidth = tooltipEl.outerWidth();
tooltipEl.css({
visibility: 'visible',
left: canvasOffsetLeft + item.x - tooltipWidth / 2,
top: canvasOffsetTop
});
},
onHide() {
const tooltipEl = $('#tooltip');
tooltipEl.css({
visibility: 'hidden'
});
}
});
chart.area().position('date*steps').style({
fill: grd,
fillOpacity: 1
});
chart.line().position('date*steps').color('#EFDBFF').size(1.5);
chart.point().position('date*steps').color('#EED5FF').size(2.5);
chart.render();
</script>
</body>
</html>