-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chart.defaults.global y AXIS/Tooltip Formating Example #3294
Comments
@cgountanis what are you looking to achieve? |
I was hoping that I could get away with using a global setting to set the y On Sep 12, 2016 6:46 PM, "Evert Timberg" notifications@github.com wrote:
|
You can definitely use global options to control that. For instance, here's how you would update so that all linear scales (the default Y axis) will format using dollar signs and nice numbers Chart.scaleService.updateScaleDefaults('linear', {
ticks: {
callback: function(tick) {
return '$' + tick.toLocaleString();
}
}
}); Here's how you could also do the same for a tooltip Chart.defaults.global.tooltips.callbacks.label = function(tooltipItem, data) {
var dataset = data.datasets[tooltipItem.datasetIndex];
var datasetLabel = dataset.label || '';
return datasetLabel + ": $" + dataset.data[tooltipItem.index].toLocaleString();
}); I've hesitated to push to include these in the core because there are so many different options and trying to support each and every one would dramatically increase the size of the already large library. It may make sense to encourage someone to create a library of formatters that essentially automates the creation of these functions to speed up development. |
I am leaving the stack post here including working JSFiddle which might help others someday. http://stackoverflow.com/questions/39453720/chart-js-globally-formatted-number-labels |
Thanks @cgountanis |
Can I please get an example of using the global options to setup a simple comma formatted Y and tooltip label? I am not able to get anything to work right.
The text was updated successfully, but these errors were encountered: