From 398b4ce19fe6fee79a56705e46d240d2f3e22346 Mon Sep 17 00:00:00 2001 From: sbosse Date: Mon, 21 Jul 2025 23:35:20 +0200 Subject: [PATCH] Mon 21 Jul 22:43:21 CEST 2025 --- js/ui/chart/docs/configuration/README.md | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 js/ui/chart/docs/configuration/README.md diff --git a/js/ui/chart/docs/configuration/README.md b/js/ui/chart/docs/configuration/README.md new file mode 100644 index 0000000..0a4dee4 --- /dev/null +++ b/js/ui/chart/docs/configuration/README.md @@ -0,0 +1,33 @@ +# Configuration + +The configuration is used to change how the chart behaves. There are properties to control styling, fonts, the legend, etc. + +## Global Configuration + +This concept was introduced in Chart.js 1.0 to keep configuration [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself), and allow for changing options globally across chart types, avoiding the need to specify options for each instance, or the default for a particular chart type. + +Chart.js merges the options object passed to the chart with the global configuration using chart type defaults and scales defaults appropriately. This way you can be as specific as you would like in your individual chart configuration, while still changing the defaults for all chart types where applicable. The global general options are defined in `Chart.defaults.global`. The defaults for each chart type are discussed in the documentation for that chart type. + +The following example would set the hover mode to 'nearest' for all charts where this was not overridden by the chart type defaults or the options passed to the constructor on creation. + +```javascript +Chart.defaults.global.hover.mode = 'nearest'; + +// Hover mode is set to nearest because it was not overridden here +var chartHoverModeNearest = new Chart(ctx, { + type: 'line', + data: data +}); + +// This chart would have the hover mode that was passed in +var chartDifferentHoverMode = new Chart(ctx, { + type: 'line', + data: data, + options: { + hover: { + // Overrides the global setting + mode: 'index' + } + } +}); +```