Skip to content

Commit 4d609f2

Browse files
committed
minor #1837 [Chartjs] Improve Y axis formatting example (hellomedia)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Chartjs] Improve Y axis formatting example | Q | A | ------------- | --- | Bug fix? | misleading doc fix | New feature? | no | Issues | see description | License | MIT Code example in the doc does not just format Y axis, it overrides existing `scales` configuration. ```js // For instance you can format Y axis event.detail.config.options.scales = { y: { ticks: { callback: function (value, index, values) { /* ... */ }, }, }, }; ``` This code formats the y-axis and keeps an existing `scales` config untouched, but requires an existing Y axis config. ```js // For instance you can format Y axis event.detail.config.options.scales.y.ticks = { callback: function (value, index, values) { /* ... */ } }; ``` Commits ------- 101b3e9 [Chartjs] Improve Y axis formatting example
2 parents 796dd58 + 101b3e9 commit 4d609f2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Chartjs/doc/index.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ custom Stimulus controller:
185185
console.log(event.detail.config);
186186
187187
// For instance you can format Y axis
188+
// To avoid overriding existing config, you should distinguish 3 cases:
189+
// # 1. No existing scales config => add a new scales config
188190
event.detail.config.options.scales = {
189191
y: {
190192
ticks: {
@@ -194,6 +196,20 @@ custom Stimulus controller:
194196
},
195197
},
196198
};
199+
// # 2. Existing scales config without Y axis config => add new Y axis config
200+
event.detail.config.options.scales.y = {
201+
ticks: {
202+
callback: function (value, index, values) {
203+
/* ... */
204+
},
205+
},
206+
};
207+
// # 3. Existing Y axis config => update it
208+
event.detail.config.options.scales.y.ticks = {
209+
callback: function (value, index, values) {
210+
/* ... */
211+
},
212+
};
197213
}
198214
199215
_onConnect(event) {

0 commit comments

Comments
 (0)