Last active
January 17, 2025 22:43
-
-
Save miko007/a781e071f6f7035a30dd281aba042b2a to your computer and use it in GitHub Desktop.
This is a simple "currency scale" to register with Charts.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CurrencyScale extends Chart.LinearScale { | |
static id = "currency"; | |
static defaults = { | |
currency : "USD", | |
locale : "en-US" | |
}; | |
getLabelForValue(value) { | |
return this.formatCurrency(value); | |
} | |
generateTickLabels(ticks) { | |
ticks.map(tick => tick.label = this.formatCurrency(tick.value)); | |
} | |
formatCurrency(value) { | |
return new Intl.NumberFormat(this.options.locale, {style : "currency", currency: this.options.currency}).format(value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you then can simply add the type to your
scales
config object, after you registered the scale: