]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Update tooltip docs with working example (#6918)
authorEvert Timberg <evert.timberg+github@gmail.com>
Mon, 6 Jan 2020 22:49:36 +0000 (17:49 -0500)
committerGitHub <noreply@github.com>
Mon, 6 Jan 2020 22:49:36 +0000 (17:49 -0500)
docs/configuration/tooltip.md

index 7c662b2883ce8fd3271058e0d65c8798f29f80ed..d57568b7f4feb5d04c2aeb254f6b55cdf29790bf 100644 (file)
@@ -121,7 +121,7 @@ All functions are called with the same arguments: a [tooltip item](#tooltip-item
 
 ### Label Callback
 
-The `label` callback can change the text that displays for a given data point. A common example to round data values; the following example rounds the data to two decimal places.
+The `label` callback can change the text that displays for a given data point. A common example to show a unit. The example below puts a `'$'` before every row.
 
 ```javascript
 var chart = new Chart(ctx, {
@@ -136,7 +136,9 @@ var chart = new Chart(ctx, {
                     if (label) {
                         label += ': ';
                     }
-                    label += Math.round(tooltipItem.value * 100) / 100;
+                    if (!helpers.isNullOrUndef(tooltipItem.value)) {
+                        label += '$' + tooltipItem.value;
+                    }
                     return label;
                 }
             }