Skip to content

Commit 40d432a

Browse files
authored
docs: update histogram demo (#6706)
1 parent 2a591b1 commit 40d432a

File tree

2 files changed

+20
-46
lines changed

2 files changed

+20
-46
lines changed

site/examples/general/histogram/demo/histogram-stacked.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
import DataSet from '@antv/data-set';
21
import { Chart } from '@antv/g2';
32

43
fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/diamond.json')
54
.then((res) => res.json())
65
.then((data) => {
7-
const ds = new DataSet();
8-
const dv = ds.createView().source(data);
9-
dv.transform({
10-
type: 'bin.histogram',
11-
field: 'depth',
12-
binWidth: 1,
13-
groupBy: ['cut'],
14-
as: ['depth', 'count'],
15-
});
16-
176
const chart = new Chart({
187
container: 'container',
198
autoFit: true,
@@ -25,14 +14,15 @@ fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/diamond.json')
2514
.encode('x', 'depth')
2615
.encode('y', 'count')
2716
.encode('color', 'cut')
28-
.data(dv.rows)
29-
.scale({
30-
depth: {
31-
tickInterval: 1,
32-
},
33-
count: {
34-
nice: true,
35-
},
17+
.data(data)
18+
.transform({
19+
type: 'binX',
20+
y: 'count',
21+
thresholds: 25,
22+
})
23+
.style({
24+
columnWidthRatio: 1,
25+
inset: 0.5,
3626
});
3727

3828
chart.render();
Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
1-
import DataSet from '@antv/data-set';
21
import { Chart } from '@antv/g2';
32

4-
const values = [
3+
const data = [
54
1.2, 3.4, 3.7, 4.3, 5.2, 5.8, 6.1, 6.5, 6.8, 7.1, 7.3, 7.7, 8.3, 8.6, 8.8,
65
9.1, 9.2, 9.4, 9.5, 9.7, 10.5, 10.7, 10.8, 11.0, 11.0, 11.1, 11.2, 11.3, 11.4,
76
11.4, 11.7, 12.0, 12.9, 12.9, 13.3, 13.7, 13.8, 13.9, 14.0, 14.2, 14.5, 15,
87
15.2, 15.6, 16.0, 16.3, 17.3, 17.5, 17.9, 18.0, 18.0, 20.6, 21, 23.4,
98
];
109

11-
const data = values.map((value) => {
12-
return {
13-
value,
14-
};
15-
});
16-
const ds = new DataSet();
17-
const dv = ds.createView().source(data);
18-
dv.transform({
19-
type: 'bin.histogram',
20-
field: 'value',
21-
binWidth: 2,
22-
as: ['value', 'count'],
23-
});
24-
2510
const chart = new Chart({
2611
container: 'container',
2712
autoFit: true,
@@ -30,18 +15,17 @@ const chart = new Chart({
3015

3116
chart
3217
.interval()
33-
.encode('x', 'value')
18+
.data(data)
19+
.encode('x', (d) => d)
3420
.encode('y', 'count')
35-
.data(dv.rows)
36-
.scale({
37-
value: {
38-
min: 0,
39-
tickInterval: 2,
40-
},
41-
count: {
42-
max: 14,
43-
nice: true,
44-
},
21+
.transform({
22+
type: 'binX',
23+
y: 'count',
24+
thresholds: 10,
25+
})
26+
.style({
27+
columnWidthRatio: 1,
28+
inset: 0.5,
4529
});
4630

4731
chart.render();

0 commit comments

Comments
 (0)