Skip to content

Commit

Permalink
Docs/clarify usage of ticks callback (#9991) (#9994)
Browse files Browse the repository at this point in the history
* Docs/clarify usage of ticks callback (#9991)

* Docs/Fixed inconsistent variable names (#9991)

Co-authored-by: Doug Brunner <doug@epicycloidengr.com>
  • Loading branch information
doug-a-brunner and Doug Brunner committed Dec 16, 2021
1 parent 30bebef commit 977a4b8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion docs/axes/labelling.md
Expand Up @@ -45,7 +45,7 @@ const chart = new Chart(ctx, {
y: {
ticks: {
// Include a dollar sign in the ticks
callback: function(value, index, values) {
callback: function(value, index, ticks) {
return '$' + value;
}
}
Expand All @@ -55,6 +55,13 @@ const chart = new Chart(ctx, {
});
```

Keep in mind that overriding `ticks.callback` means that you are responsible for all formatting of the label. Depending on your use case, you may want to call the default formatter and then modify its output. In the example above, that would look like:

```javascript
// call the default formatter, forwarding `this`
return '$' + Chart.Ticks.formatters.numeric.apply(this, [value, index, ticks]);
```

Related samples:

* [Tick configuration sample](../samples/scale-options/ticks)

0 comments on commit 977a4b8

Please sign in to comment.