]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Docs/clarify usage of ticks callback (#9991) (#9994)
authorDoug Brunner <doug.a.brunner@gmail.com>
Thu, 16 Dec 2021 12:34:30 +0000 (04:34 -0800)
committerGitHub <noreply@github.com>
Thu, 16 Dec 2021 12:34:30 +0000 (07:34 -0500)
* Docs/clarify usage of ticks callback (#9991)

* Docs/Fixed inconsistent variable names (#9991)

Co-authored-by: Doug Brunner <doug@epicycloidengr.com>
docs/axes/labelling.md

index 83c365807686651797f39e9e2549625291da7a9d..9ab75ffaba08f6cc8c56d7d5d1dde22e6cd1f6c3 100644 (file)
@@ -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;
                     }
                 }
@@ -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)