Skip to content

Commit 5a06494

Browse files
authored
chore: add sample for minRange on category scale (#873)
1 parent 6456d46 commit 5a06494

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

docs/.vuepress/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ module.exports = {
134134
title: 'Wheel Zoom',
135135
children: [
136136
'wheel/category',
137+
'wheel/category-min-range',
137138
'wheel/log',
138139
'wheel/time',
139140
'wheel/over-scale-mode',
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Category Scale + minRange
2+
3+
```js chart-editor
4+
// <block:data:1>
5+
const DATA_COUNT = 20;
6+
const NUMBER_CFG = {count: DATA_COUNT, min: -100, max: 100};
7+
const data = {
8+
labels: Utils.months({count: DATA_COUNT}),
9+
datasets: [{
10+
label: 'Dataset 1',
11+
borderColor: Utils.randomColor(0.7),
12+
backgroundColor: Utils.randomColor(0.5),
13+
data: Utils.numbers(NUMBER_CFG),
14+
}, {
15+
label: 'Dataset 2',
16+
borderColor: Utils.randomColor(0.7),
17+
backgroundColor: Utils.randomColor(0.5),
18+
data: Utils.numbers(NUMBER_CFG),
19+
}, {
20+
label: 'Dataset 3',
21+
borderColor: Utils.randomColor(0.7),
22+
backgroundColor: Utils.randomColor(0.5),
23+
data: Utils.numbers(NUMBER_CFG),
24+
}]
25+
};
26+
// </block:data>
27+
28+
// <block:scales:2>
29+
const scaleOpts = {
30+
grid: {
31+
borderColor: Utils.randomColor(1),
32+
color: 'rgba( 0, 0, 0, 0.1)',
33+
},
34+
title: {
35+
display: true,
36+
text: (ctx) => ctx.scale.axis + ' axis',
37+
}
38+
};
39+
const scales = {
40+
x: {
41+
type: 'category',
42+
min: 5,
43+
max: 11,
44+
},
45+
y: {
46+
type: 'linear'
47+
},
48+
};
49+
Object.keys(scales).forEach(scale => Object.assign(scales[scale], scaleOpts));
50+
// </block:scales>
51+
52+
// <block:config:0>
53+
const config = {
54+
type: 'bar',
55+
data: data,
56+
options: {
57+
scales: scales,
58+
plugins: {
59+
zoom: {
60+
pan: {
61+
enabled: true,
62+
mode: 'x',
63+
threshold: 5,
64+
},
65+
zoom: {
66+
wheel: {
67+
enabled: true
68+
},
69+
pinch: {
70+
enabled: true
71+
},
72+
mode: 'x',
73+
},
74+
limits: {
75+
x: {
76+
minRange: 4
77+
}
78+
}
79+
},
80+
},
81+
}
82+
};
83+
// </block:config>
84+
85+
const actions = [
86+
{
87+
name: 'Reset zoom',
88+
handler(chart) {
89+
chart.resetZoom();
90+
}
91+
}
92+
];
93+
94+
module.exports = {
95+
actions,
96+
config,
97+
};
98+
```

0 commit comments

Comments
 (0)