This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
79 lines (75 loc) · 1.88 KB
/
index.js
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
import F2 from '@antv/my-f2';
const app = getApp();
let chart = null;
function drawChart(canvas, width, height) {
var data = [
{ year: '1951 年', sales: 38 },
{ year: '1952 年', sales: 52 },
{ year: '1956 年', sales: 61 },
{ year: '1957 年', sales: 145 },
{ year: '1958 年', sales: 48 },
{ year: '1959 年', sales: 38 },
{ year: '1960 年', sales: 38 },
{ year: '1962 年', sales: 38 },
];
var chart = new F2.Chart({
el: canvas,
width,
height
});
chart.source(data, {
sales: {
tickCount: 5
}
});
chart.tooltip({
showItemMarker: false,
onShow: function(ev) {
var items = ev.items;
items[0].name = null;
items[0].name = items[0].title;
items[0].value = '¥ ' + items[0].value;
}
});
chart.interval().position('year*sales');
chart.render();
}
Page({
data: {},
onReady() {
my.createSelectorQuery()
.select('#column')
.boundingClientRect()
.exec((res) => {
// 获取分辨率
const pixelRatio = my.getSystemInfoSync().pixelRatio;
// 获取画布实际宽高
const canvasWidth = res[0].width;
const canvasHeight = res[0].height;
this.setData({
width: canvasWidth * pixelRatio,
height: canvasHeight * pixelRatio
});
const myCtx = my.createCanvasContext('column');
myCtx.scale(pixelRatio, pixelRatio); // 必要!按照设置的分辨率进行放大
const canvas = new F2.Renderer(myCtx);
this.canvas = canvas;
drawChart(canvas, res[0].width, res[0].height);
});
},
touchStart(e) {
if (this.canvas) {
this.canvas.emitEvent('touchstart', [e]);
}
},
touchMove(e) {
if (this.canvas) {
this.canvas.emitEvent('touchmove', [e]);
}
},
touchEnd(e) {
if (this.canvas) {
this.canvas.emitEvent('touchend', [e]);
}
}
});