Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/axes/labelling.md
Original file line number Diff line number Diff line change
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`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there's some leading whitespace here which could be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the leading whitespace the same as in the example above, to emphasize that the snippet would substitute for return '$' + value;.

return '$' + Chart.Ticks.formatters.numeric.apply(this, [value, index, ticks]);
```

Related samples:

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