]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Changed var to const/let in the docs (#9744)
authorPrashoonB <prashoonbhattacharjee@gmail.com>
Wed, 13 Oct 2021 18:51:33 +0000 (00:21 +0530)
committerGitHub <noreply@github.com>
Wed, 13 Oct 2021 18:51:33 +0000 (14:51 -0400)
Changed var to const/let in the docs

52 files changed:
docs/axes/cartesian/index.md
docs/axes/cartesian/time.md
docs/axes/cartesian/timeseries.md
docs/axes/labelling.md
docs/charts/bar.md
docs/charts/line.md
docs/charts/mixed.md
docs/configuration/animations.md
docs/configuration/index.md
docs/configuration/interactions.md
docs/configuration/legend.md
docs/configuration/responsive.md
docs/configuration/subtitle.md
docs/configuration/title.md
docs/configuration/tooltip.md
docs/developers/api.md
docs/developers/axes.md
docs/developers/plugins.md
docs/developers/updates.md
docs/general/colors.md
docs/general/options.md
docs/getting-started/index.md
docs/getting-started/integration.md
docs/getting-started/usage.md
docs/index.md
docs/samples/advanced/linear-gradient.md
docs/samples/advanced/progress-bar.md
docs/samples/advanced/radial-gradient.md
docs/samples/animations/delay.md
docs/samples/animations/drop.md
docs/samples/animations/loop.md
docs/samples/area/line-stacked.md
docs/samples/bar/horizontal.md
docs/samples/bar/vertical.md
docs/samples/line/line.md
docs/samples/other-charts/bubble.md
docs/samples/other-charts/combo-bar-line.md
docs/samples/other-charts/doughnut.md
docs/samples/other-charts/multi-series-pie.md
docs/samples/other-charts/pie.md
docs/samples/other-charts/polar-area.md
docs/samples/other-charts/radar.md
docs/samples/other-charts/scatter-multi-axis.md
docs/samples/other-charts/scatter.md
docs/samples/other-charts/stacked-bar-line.md
docs/samples/scales/linear-step-size.md
docs/samples/scriptable/bar.md
docs/samples/scriptable/bubble.md
docs/samples/scriptable/line.md
docs/samples/scriptable/pie.md
docs/samples/scriptable/polar.md
docs/samples/scriptable/radar.md

index a824576ffa6b56a78fb25b1431644cb9cc0c9c3c..6054f4d84a7e9da9ecaa2945534a776a2dab1f8c 100644 (file)
@@ -294,7 +294,7 @@ The `crossAlign` setting is only effective when these preconditions are met:
 The properties `dataset.xAxisID` or `dataset.yAxisID` have to match to `scales` property. This is especially needed if multi-axes charts are used.
 
 ```javascript
-var myChart = new Chart(ctx, {
+const myChart = new Chart(ctx, {
     type: 'line',
     data: {
         datasets: [{
@@ -325,7 +325,7 @@ With cartesian axes, it is possible to create multiple X and Y axes. To do so, y
 In the example below, we are creating two Y axes. We then use the `yAxisID` property to map the datasets to their correct axes.
 
 ```javascript
-var myChart = new Chart(ctx, {
+const myChart = new Chart(ctx, {
     type: 'line',
     data: {
         datasets: [{
index 3ec4755ab528fdb9102261587a01a848db82d912..5c609d2175da7083875d6119887c3d33306046f9 100644 (file)
@@ -57,7 +57,7 @@ The following time measurements are supported. The names can be passed as string
 For example, to create a chart with a time scale that always displayed units per month, the following config could be used.
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
@@ -92,7 +92,7 @@ The format string used as a value depends on the date adapter you chose to use.
 For example, to set the display format for the `quarter` unit to show the month and year, the following config might be passed to the chart constructor.
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
index ab7f978a92c5fb1904ece94018b5cccf757fa78c..daac4df28bf55aa0b02bd023ef0e98c0b57d93a2 100644 (file)
@@ -5,7 +5,7 @@ The time series scale extends from the time scale and supports all the same opti
 ## Example
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
index 527e53fd175956010533da89afadee0696c39bd1..4f0496e3b86d16c843b57246499a639cb6137c61 100644 (file)
@@ -37,7 +37,7 @@ The [category axis](../axes/cartesian/category), which is the default x-axis for
 In the following example, every label of the Y-axis would be displayed with a dollar sign at the front.
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
index 325ca9c3678f3d1e42f807fefdd2fa1942283c93..261beec470e188830e7ab5b65a19694d744435e5 100644 (file)
@@ -278,7 +278,7 @@ All of the supported [data structures](../general/data-structures.md) can be use
 Bar charts can be configured into stacked bar charts by changing the settings on the X and Y axes to enable stacking. Stacked bar charts can be used to show how one data series is made up of a number of smaller pieces.
 
 ```javascript
-var stackedBar = new Chart(ctx, {
+const stackedBar = new Chart(ctx, {
     type: 'bar',
     data: data,
     options: {
index fc245fcb035309466ae71f4d67da09933d95c19d..bfd9927d175642823f278c3cf3c0d39dc989c369 100644 (file)
@@ -209,7 +209,7 @@ All of the supported [data structures](../general/data-structures.md) can be use
 Line charts can be configured into stacked area charts by changing the settings on the y-axis to enable stacking. Stacked area charts can be used to show how one data trend is made up of a number of smaller pieces.
 
 ```javascript
-var stackedLine = new Chart(ctx, {
+const stackedLine = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
index 84f42f1303c391a41075eae30c97452fbb603736..79bf9b6e01c33b0615183807a1d600d0ee811ebb 100644 (file)
@@ -5,7 +5,7 @@ With Chart.js, it is possible to create mixed charts that are a combination of t
 When creating a mixed chart, we specify the chart type on each dataset.
 
 ```javascript
-var mixedChart = new Chart(ctx, {
+const mixedChart = new Chart(ctx, {
     data: {
         datasets: [{
             type: 'bar',
@@ -76,7 +76,7 @@ module.exports = {
 The `order` property behaves like a weight instead of a specific order, so the higher the number, the sooner that dataset is drawn on the canvas and thus other datasets with a lower order number will get drawn over it.
 
  ```javascript
-var mixedChart = new Chart(ctx, {
+const mixedChart = new Chart(ctx, {
     type: 'bar',
     data: {
         datasets: [{
index 36ac0e7c11c125f974a943bf22879be6605db19b..21b5994bf16638b439d2e06dae4b47cf58a0e635 100644 (file)
@@ -269,7 +269,7 @@ The callback is passed the following object:
 The following example fills a progress bar during the chart animation.
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
index a5193bf31e593f3d3a7f000f58d0e3137baeb1b1..b689fc328ea70e7a23ab20851b583672b523ae47 100644 (file)
@@ -14,13 +14,13 @@ The following example would set the interaction mode to 'nearest' for all charts
 Chart.defaults.interaction.mode = 'nearest';
 
 // Interaction mode is set to nearest because it was not overridden here
-var chartInteractionModeNearest = new Chart(ctx, {
+const chartInteractionModeNearest = new Chart(ctx, {
     type: 'line',
     data: data
 });
 
 // This chart would have the interaction mode that was passed in
-var chartDifferentInteractionMode = new Chart(ctx, {
+const chartDifferentInteractionMode = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
@@ -43,7 +43,7 @@ The following example would set the `showLine` option to 'false' for all line da
 Chart.defaults.datasets.line.showLine = false;
 
 // This chart would show a line only for the third dataset
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: {
         datasets: [{
index 370244bae415456fd5e14ebc88e95cddba4d4967..a2b92449583d4eaf803972840d309f73a40c30da 100644 (file)
@@ -26,7 +26,7 @@ Namespace: `options`
 For example, to have the chart only respond to click events, you could do:
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
   type: 'line',
   data: data,
   options: {
@@ -39,7 +39,7 @@ var chart = new Chart(ctx, {
 Events for each plugin can be further limited by defining (allowed) events array in plugin options:
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
   type: 'line',
   data: data,
   options: {
@@ -59,7 +59,7 @@ var chart = new Chart(ctx, {
 Events that do not fire over chartArea, like `mouseout`, can be captured using a simple plugin:
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
   type: 'line',
   data: data,
   options: {
@@ -113,7 +113,7 @@ The modes are detailed below and how they behave in conjunction with the `inters
 Finds all of the items that intersect the point.
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
@@ -129,7 +129,7 @@ var chart = new Chart(ctx, {
 Gets the items that are at the nearest distance to the point. The nearest item is determined based on the distance to the center of the chart item (point, bar). You can use the `axis` setting to define which directions are used in distance calculation. If `intersect` is true, this is only triggered when the mouse position intersects an item in the graph. This is very useful for combo charts where points are hidden behind bars.
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
@@ -145,7 +145,7 @@ var chart = new Chart(ctx, {
 Finds item at the same index. If the `intersect` setting is true, the first intersecting item is used to determine the index in the data. If `intersect` false the nearest item, in the x direction, is used to determine the index.
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
@@ -159,7 +159,7 @@ var chart = new Chart(ctx, {
 To use index mode in a chart like the horizontal bar chart, where we search along the y direction, you can use the `axis` setting introduced in v2.7.0. By setting this value to `'y'` on the y direction is used.
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'bar',
     data: data,
     options: {
@@ -176,7 +176,7 @@ var chart = new Chart(ctx, {
 Finds items in the same dataset. If the `intersect` setting is true, the first intersecting item is used to determine the index in the data. If `intersect` false the nearest item is used to determine the index.
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
@@ -192,7 +192,7 @@ var chart = new Chart(ctx, {
 Returns all items that would intersect based on the `X` coordinate of the position only. Would be useful for a vertical cursor implementation. Note that this only applies to cartesian charts.
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
@@ -208,7 +208,7 @@ var chart = new Chart(ctx, {
 Returns all items that would intersect based on the `Y` coordinate of the position. This would be useful for a horizontal cursor implementation. Note that this only applies to cartesian charts.
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
index 876ae11e4fbdb7f197e2c704c00e953a4e075938..10fa89cd32a61b36fd0066597f7ad73a8b721b6c 100644 (file)
@@ -131,7 +131,7 @@ Items passed to the legend `onClick` function are the ones returned from `labels
 The following example will create a chart with the legend enabled and turn all of the text red in color.
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'bar',
     data: data,
     options: {
@@ -170,11 +170,11 @@ function(e, legendItem, legend) {
 Lets say we wanted instead to link the display of the first two datasets. We could change the click handler accordingly.
 
 ```javascript
-var defaultLegendClickHandler = Chart.defaults.plugins.legend.onClick;
-var pieDoughnutLegendClickHandler = Chart.controllers.doughnut.overrides.plugins.legend.onClick;
-var newLegendClickHandler = function (e, legendItem, legend) {
-    var index = legendItem.datasetIndex;
-    var type = legend.chart.config.type;
+const defaultLegendClickHandler = Chart.defaults.plugins.legend.onClick;
+const pieDoughnutLegendClickHandler = Chart.controllers.doughnut.overrides.plugins.legend.onClick;
+const newLegendClickHandler = function (e, legendItem, legend) {
+    const index = legendItem.datasetIndex;
+    const type = legend.chart.config.type;
 
     if (index > 1) {
         // Do the original logic
@@ -196,7 +196,7 @@ var newLegendClickHandler = function (e, legendItem, legend) {
     }
 };
 
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
index 8f2564b1d1d4f82545fbe2a89c61b273fbe8d08b..3254ccb8cb6812e2645322d5e4cdc3f570fef6b4 100644 (file)
@@ -47,7 +47,7 @@ CSS media queries allow changing styles when printing a page. The CSS applied fr
 
 ```javascript
 function beforePrintHandler () {
-    for (var id in Chart.instances) {
+    for (let id in Chart.instances) {
         Chart.instances[id].resize();
     }
 }
index 41fa26d077f1aa7f4ae06baec2b59ba3d906be0c..e50f08f022cfe68c323fbccd3ec66faea2f75459 100644 (file)
@@ -13,7 +13,7 @@ Excactly the same configuration options with [title](./title.md) are available f
 The example below would enable a title of 'Custom Chart Subtitle' on the chart that is created.
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
index 3bd78c07d2a4166fc9a34e37620cebab005289f3..f15b25b4b791eed2b23e7664b9bdd486da67b8cd 100644 (file)
@@ -39,7 +39,7 @@ Alignment of the title. Options are:
 The example below would enable a title of 'Custom Chart Title' on the chart that is created.
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
@@ -56,7 +56,7 @@ var chart = new Chart(ctx, {
 This example shows how to specify separate top and bottom title text padding:
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
index 2c68ed9d773bf9476d7805985c5eb94e3f4a7ba8..bac1a0b94078905d123e812a793ca3327b6db12b 100644 (file)
@@ -70,7 +70,7 @@ Example:
 const tooltipPlugin = Chart.registry.getPlugin('tooltip');
 tooltipPlugin.positioners.myCustomPositioner = function(elements, eventPosition) {
     /** @type {Tooltip} */
-    var tooltip = this;
+    const tooltip = this;
 
     /* ... */
 
@@ -145,7 +145,7 @@ A [tooltip item context](#tooltip-item-context) is generated for each item that
 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, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
@@ -153,7 +153,7 @@ var chart = new Chart(ctx, {
             tooltip: {
                 callbacks: {
                     label: function(context) {
-                        var label = context.dataset.label || '';
+                        const label = context.dataset.label || '';
 
                         if (label) {
                             label += ': ';
@@ -175,7 +175,7 @@ var chart = new Chart(ctx, {
 For example, to return a red box with a blue dashed border that has a border radius for each item in the tooltip you could do:
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
@@ -206,7 +206,7 @@ var chart = new Chart(ctx, {
 For example, to draw triangles instead of the regular color box for each item in the tooltip you could do:
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     type: 'line',
     data: data,
     options: {
@@ -267,7 +267,7 @@ The tooltip items passed to the tooltip callbacks implement the following interf
 External tooltips allow you to hook into the tooltip rendering process so that you can render the tooltip in your own custom way. Generally this is used to create an HTML tooltip instead of an on-canvas tooltip. The `external` option takes a function which is passed a context parameter containing the `chart` and `tooltip`. You can enable external tooltips in the global or chart configuration like so:
 
 ```javascript
-var myPieChart = new Chart(ctx, {
+const myPieChart = new Chart(ctx, {
     type: 'pie',
     data: data,
     options: {
@@ -278,7 +278,7 @@ var myPieChart = new Chart(ctx, {
 
                 external: function(context) {
                     // Tooltip Element
-                    var tooltipEl = document.getElementById('chartjs-tooltip');
+                    const tooltipEl = document.getElementById('chartjs-tooltip');
 
                     // Create element on first render
                     if (!tooltipEl) {
@@ -289,7 +289,7 @@ var myPieChart = new Chart(ctx, {
                     }
 
                     // Hide if no tooltip
-                    var tooltipModel = context.tooltip;
+                    const tooltipModel = context.tooltip;
                     if (tooltipModel.opacity === 0) {
                         tooltipEl.style.opacity = 0;
                         return;
@@ -309,10 +309,10 @@ var myPieChart = new Chart(ctx, {
 
                     // Set Text
                     if (tooltipModel.body) {
-                        var titleLines = tooltipModel.title || [];
-                        var bodyLines = tooltipModel.body.map(getBody);
+                        const titleLines = tooltipModel.title || [];
+                        const bodyLines = tooltipModel.body.map(getBody);
 
-                        var innerHtml = '<thead>';
+                        const innerHtml = '<thead>';
 
                         titleLines.forEach(function(title) {
                             innerHtml += '<tr><th>' + title + '</th></tr>';
@@ -320,21 +320,21 @@ var myPieChart = new Chart(ctx, {
                         innerHtml += '</thead><tbody>';
 
                         bodyLines.forEach(function(body, i) {
-                            var colors = tooltipModel.labelColors[i];
-                            var style = 'background:' + colors.backgroundColor;
+                            const colors = tooltipModel.labelColors[i];
+                            const style = 'background:' + colors.backgroundColor;
                             style += '; border-color:' + colors.borderColor;
                             style += '; border-width: 2px';
-                            var span = '<span style="' + style + '"></span>';
+                            const span = '<span style="' + style + '"></span>';
                             innerHtml += '<tr><td>' + span + body + '</td></tr>';
                         });
                         innerHtml += '</tbody>';
 
-                        var tableRoot = tooltipEl.querySelector('table');
+                        const tableRoot = tooltipEl.querySelector('table');
                         tableRoot.innerHTML = innerHtml;
                     }
 
-                    var position = context.chart.canvas.getBoundingClientRect();
-                    var bodyFont = Chart.helpers.toFont(tooltipModel.options.bodyFont);
+                    const position = context.chart.canvas.getBoundingClientRect();
+                    const bodyFont = Chart.helpers.toFont(tooltipModel.options.bodyFont);
 
                     // Display, position, and set styles for font
                     tooltipEl.style.opacity = 1;
index a17b2a5d6b771a23b74b3b6d3974b548a9b8e7ab..beec9fdaa05b94b9cf4c2736733dde821cf27d6b 100644 (file)
@@ -4,7 +4,7 @@ For each chart, there are a set of global prototype methods on the shared chart
 
 ```javascript
 // For example:
-var myLineChart = new Chart(ctx, config);
+const myLineChart = new Chart(ctx, config);
 ```
 
 ## .destroy()
@@ -107,8 +107,8 @@ function clickHandler(evt) {
 
     if (points.length) {
         const firstPoint = points[0];
-        var label = myChart.data.labels[firstPoint.index];
-        var value = myChart.data.datasets[firstPoint.datasetIndex].data[firstPoint.index];
+        const label = myChart.data.labels[firstPoint.index];
+        const value = myChart.data.datasets[firstPoint.datasetIndex].data[firstPoint.index];
     }
 }
 ```
@@ -122,8 +122,8 @@ The `data` property of the metadata will contain information about each point, b
 Extensive examples of usage are available in the [Chart.js tests](https://github.com/chartjs/Chart.js/tree/master/test).
 
 ```javascript
-var meta = myChart.getDatasetMeta(0);
-var x = meta.data[0].x;
+const meta = myChart.getDatasetMeta(0);
+const x = meta.data[0].x;
 ```
 
 ## setDatasetVisibility(datasetIndex, visibility)
@@ -149,7 +149,7 @@ chart.update(); // chart now renders with item hidden
 Returns the stored visibility state of an data index for all datasets. Set by [toggleDataVisibility](#toggleDataVisibility). A dataset controller should use this method to determine if an item should not be visible.
 
 ```javascript
-var visible = chart.getDataVisibility(2);
+const visible = chart.getDataVisibility(2);
 ```
 
 ## hide(datasetIndex, dataIndex?)
index 6bc4507126c9f2c0ac6f8f4bc194f9c8e239f3d7..6512371270a89efd9449d8468a1e3b290388d7a1 100644 (file)
@@ -26,7 +26,7 @@ Chart.register(MyScale);
 To use the new scale, simply pass in the string key to the config when creating a chart.
 
 ```javascript
-var lineChart = new Chart(ctx, {
+const lineChart = new Chart(ctx, {
     data: data,
     type: 'line',
     options: {
index 0144839c3b2ffb092f6534aaec0f385fab47b59e..64efe2096bad98ac27b8474de9dc878e1f754905 100644 (file)
@@ -7,19 +7,19 @@ Plugins are the most efficient way to customize or change the default behavior o
 Plugins can be shared between chart instances:
 
 ```javascript
-var plugin = { /* plugin implementation */ };
+const plugin = { /* plugin implementation */ };
 
 // chart1 and chart2 use "plugin"
-var chart1 = new Chart(ctx, {
+const chart1 = new Chart(ctx, {
     plugins: [plugin]
 });
 
-var chart2 = new Chart(ctx, {
+const chart2 = new Chart(ctx, {
     plugins: [plugin]
 });
 
 // chart3 doesn't use "plugin"
-var chart3 = new Chart(ctx, {});
+const chart3 = new Chart(ctx, {});
 ```
 
 Plugins can also be defined directly in the chart `plugins` config (a.k.a. *inline plugins*):
@@ -29,7 +29,7 @@ Plugins can also be defined directly in the chart `plugins` config (a.k.a. *inli
 :::
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     plugins: [{
         beforeInit: function(chart, args, options) {
             //..
@@ -74,7 +74,7 @@ If a plugin is intended to be released publicly, you may want to check the [regi
 Plugin options are located under the `options.plugins` config and are scoped by the plugin ID: `options.plugins.{plugin-id}`.
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     options: {
         foo: { ... },           // chart 'foo' option
         plugins: {
@@ -101,7 +101,7 @@ Chart.register({
     // ...
 });
 
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     options: {
         plugins: {
             p1: false   // disable plugin 'p1' for this instance
@@ -113,7 +113,7 @@ var chart = new Chart(ctx, {
 To disable all plugins for a specific chart instance, set `options.plugins` to `false`:
 
 ```javascript
-var chart = new Chart(ctx, {
+const chart = new Chart(ctx, {
     options: {
         plugins: false // all plugins are disabled for this instance
     }
index d93fe28adb6d25b55c4fb91925707f39b63fc7b1..697d25bd3dece62b3b7b64514bfe6bef0ec93523 100644 (file)
@@ -66,8 +66,8 @@ Variables referencing any one from `chart.scales` would be lost after updating s
 
 ```javascript
 function updateScales(chart) {
-    var xScale = chart.scales.x;
-    var yScale = chart.scales.y;
+    const xScale = chart.scales.x;
+    const yScale = chart.scales.y;
     chart.options.scales = {
         newId: {
             display: true
index 0a65a46c4b7349acce29959aaeba93a4b8a76cb8..c9b101693ca8b1f886e88c2eaa3bbcc63fa8d732 100644 (file)
@@ -17,13 +17,13 @@ An alternative option is to pass a [CanvasPattern](https://developer.mozilla.org
 For example, if you wanted to fill a dataset with a pattern from an image you could do the following.
 
 ```javascript
-var img = new Image();
+const img = new Image();
 img.src = 'https://example.com/my_image.png';
 img.onload = function() {
-    var ctx = document.getElementById('canvas').getContext('2d');
-    var fillPattern = ctx.createPattern(img, 'repeat');
+    const ctx = document.getElementById('canvas').getContext('2d');
+    const fillPattern = ctx.createPattern(img, 'repeat');
 
-    var chart = new Chart(ctx, {
+    const chart = new Chart(ctx, {
         data: {
             labels: ['Item 1', 'Item 2', 'Item 3'],
             datasets: [{
@@ -40,7 +40,7 @@ Using pattern fills for data graphics can help viewers with vision deficiencies
 Using the [Patternomaly](https://github.com/ashiguruma/patternomaly) library you can generate patterns to fill datasets.
 
 ```javascript
-var chartData = {
+const chartData = {
     datasets: [{
         data: [45, 25, 20, 10],
         backgroundColor: [
index ebc4ce994d43ca721d7bea858b60718d7a68f151..55f90480c04ef3f5486b66caab498528c36e8daa 100644 (file)
@@ -78,14 +78,14 @@ Example:
 
 ```javascript
 color: function(context) {
-    var index = context.dataIndex;
-    var value = context.dataset.data[index];
+    const index = context.dataIndex;
+    const value = context.dataset.data[index];
     return value < 0 ? 'red' :  // draw negative values in red
         index % 2 ? 'blue' :    // else, alternate values in blue and green
         'green';
 },
 borderColor: function(context, options) {
-    var color = options.color; // resolve the value of another scriptable option: 'red', 'blue' or 'green'
+    const color = options.color; // resolve the value of another scriptable option: 'red', 'blue' or 'green'
     return Chart.helpers.color(color).lighten(0.2);
 }
 ```
index e609ffecd61a8c59b51cc951423cb7521f9406aa..25d944a206fe83d91307f05c5a568a8c1b3bb582 100644 (file)
@@ -59,7 +59,7 @@ Finally, render the chart using our configuration:
 <script>
   // === include 'setup' then 'config' above ===
 
-  var myChart = new Chart(
+  const myChart = new Chart(
     document.getElementById('myChart'),
     config
   );
index 13a87048bf340a87077f0111dd491e4544975fb4..d8f0707d16b6e5075a1293b03e135637d1af2c9d 100644 (file)
@@ -7,15 +7,15 @@ Chart.js can be integrated with plain JavaScript or with different module loader
 ```html
 <script src="path/to/chartjs/dist/chart.js"></script>
 <script>
-    var myChart = new Chart(ctx, {...});
+    const myChart = new Chart(ctx, {...});
 </script>
 ```
 
 ## Common JS
 
 ```javascript
-var Chart = require('chart.js');
-var myChart = new Chart(ctx, {...});
+const Chart = require('chart.js');
+const myChart = new Chart(ctx, {...});
 ```
 
 ## Bundlers (Webpack, Rollup, etc.)
@@ -80,7 +80,7 @@ Chart.register(
   SubTitle
 );
 
-var myChart = new Chart(ctx, {...});
+const myChart = new Chart(ctx, {...});
 ```
 
 A short registration format is also available to quickly register everything.
@@ -127,7 +127,7 @@ const chart = new Chart(ctx, {
 
 ```javascript
 require(['path/to/chartjs/dist/chart.min.js'], function(Chart){
-    var myChart = new Chart(ctx, {...});
+    const myChart = new Chart(ctx, {...});
 });
 ```
 
index 81b93d6cf84e8c62721481c33f6829257740e6f4..620245c0e91866afe4fe8421bc5931100589883c 100644 (file)
@@ -12,10 +12,10 @@ To create a chart, we need to instantiate the `Chart` class. To do this, we need
 
 ```javascript
 // Any of the following formats may be used
-var ctx = document.getElementById('myChart');
-var ctx = document.getElementById('myChart').getContext('2d');
-var ctx = $('#myChart');
-var ctx = 'myChart';
+const ctx = document.getElementById('myChart');
+const ctx = document.getElementById('myChart').getContext('2d');
+const ctx = $('#myChart');
+const ctx = 'myChart';
 ```
 
 Once you have the element or context, you're ready to instantiate a pre-defined chart-type or create your own!
@@ -25,8 +25,8 @@ The following example instantiates a bar chart showing the number of votes for d
 ```html
 <canvas id="myChart" width="400" height="400"></canvas>
 <script>
-var ctx = document.getElementById('myChart');
-var myChart = new Chart(ctx, {
+const ctx = document.getElementById('myChart');
+const myChart = new Chart(ctx, {
     type: 'bar',
     data: {
         labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
index 8e90dd040f355a8d5db49a1a1233ca06a409b699..076b2debb94fd4c212c28127897821235955c788 100644 (file)
@@ -15,8 +15,8 @@ In this example, we create a bar chart for a single dataset and render that in o
 ```html
 <canvas id="myChart" width="400" height="400"></canvas>
 <script>
-var ctx = document.getElementById('myChart').getContext('2d');
-var myChart = new Chart(ctx, {
+const ctx = document.getElementById('myChart').getContext('2d');
+const myChart = new Chart(ctx, {
     type: 'bar',
     data: {
         labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
index 4b0896353c85a2bea8cb2596a05e40759918a3f3..07d13d18d3cbdfc625007bcd3d5b45e5dd1066a5 100644 (file)
@@ -19,7 +19,7 @@ const actions = [
       if (data.datasets.length > 0) {
         data.labels = Utils.months({count: data.labels.length + 1});
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.rand(-100, 100));
         }
 
index 1ba5554dbafc68fbbfb59f1a82dfbbc4572c5443..70af7c658cdf7bdc16455b02f8f8807e780d22f7 100644 (file)
@@ -42,7 +42,7 @@ const actions = [
       if (data.datasets.length > 0) {
         data.labels = Utils.months({count: data.labels.length + 1});
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.rand(-100, 100));
         }
 
index c38833efc082eb8f89ce7fab57a9209c827fa19e..45211d6ab598b9798648c3c8b3ee32ac4587ead6 100644 (file)
@@ -38,7 +38,7 @@ function createRadialGradient3(context, c1, c2, c3) {
   if (width !== chartWidth || height !== chartHeight) {
     cache.clear();
   }
-  var gradient = cache.get(c1 + c2 + c3);
+  let gradient = cache.get(c1 + c2 + c3);
   if (!gradient) {
     // Create the gradient because this is either the first render
     // or the size of the chart has changed
@@ -50,7 +50,7 @@ function createRadialGradient3(context, c1, c2, c3) {
       (chartArea.right - chartArea.left) / 2,
       (chartArea.bottom - chartArea.top) / 2
     );
-    var ctx = context.chart.ctx;
+    const ctx = context.chart.ctx;
     gradient = ctx.createRadialGradient(centerX, centerY, 0, centerX, centerY, r);
     gradient.addColorStop(0, c1);
     gradient.addColorStop(0.5, c2);
index 3e7a8d4f9304546ec2a2e7dba65dd21d0e7d3e59..767110fe8f3044c64af2f8b8da4a8f3a2a445e1d 100644 (file)
@@ -43,7 +43,7 @@ const data = {
 // </block:setup>
 
 // <block:config:0>
-var delayed;
+let delayed;
 const config = {
   type: 'bar',
   data: data,
index bdeaeb31a374160e78a499b0089029d57780d6fc..e9401014f2a7e0f31dcec3882130d8a64e017f15 100644 (file)
@@ -34,7 +34,7 @@ const actions = [
       if (data.datasets.length > 0) {
         data.labels = Utils.months({count: data.labels.length + 1});
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.rand(-100, 100));
         }
 
index d6eeb0fc3fc96e1729d68451216a53d0ea843171..05a4a62c90c145a89773ff75860c57a91e2765db 100644 (file)
@@ -34,7 +34,7 @@ const actions = [
       if (data.datasets.length > 0) {
         data.labels = Utils.months({count: data.labels.length + 1});
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.rand(-100, 100));
         }
 
index 4394b6aee082117cc2fe040bd8bdd7432dfd6850..a03d4522515d86fdf2c7925f7f9b34a63713ec1c 100644 (file)
@@ -56,7 +56,7 @@ const actions = [
       if (data.datasets.length > 0) {
         data.labels = Utils.months({count: data.labels.length + 1});
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.rand(-100, 100));
         }
 
index a56eaa027caf82ee61629b453100f4e9fcdc45f2..f9d85b96644d7cf77e387eb05fc6489aa9fb6b0f 100644 (file)
@@ -35,7 +35,7 @@ const actions = [
       if (data.datasets.length > 0) {
         data.labels = Utils.months({count: data.labels.length + 1});
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.rand(-100, 100));
         }
 
index e5540565e89008269b3454fe35ba62428703a52a..5ce29a3f14816f05a55e13165548560d57deb008 100644 (file)
@@ -35,7 +35,7 @@ const actions = [
       if (data.datasets.length > 0) {
         data.labels = Utils.months({count: data.labels.length + 1});
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.rand(-100, 100));
         }
 
index f88a3c5e507413003cd310fc11e7aedc5c16dcb9..f157d394e2804c043f6598d4aabace27f9070049 100644 (file)
@@ -34,7 +34,7 @@ const actions = [
       if (data.datasets.length > 0) {
         data.labels = Utils.months({count: data.labels.length + 1});
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.rand(-100, 100));
         }
 
index 3d330fb19f219125d356eae3b8aa6c3fd43f028b..0276e65d8513b9ca269db75baee6f27344eee102 100644 (file)
@@ -33,7 +33,7 @@ const actions = [
       const data = chart.data;
       if (data.datasets.length > 0) {
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.bubbles({count: 1, rmin: 5, rmax: 15, min: 0, max: 100})[0]);
         }
 
index 16013d9adba881dcd98f3073edd870fdd091e37a..30fbfadbf7a48742af5e287e62a26c3c1819e11e 100644 (file)
@@ -35,7 +35,7 @@ const actions = [
       if (data.datasets.length > 0) {
         data.labels = Utils.months({count: data.labels.length + 1});
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.rand(-100, 100));
         }
 
index 21e98c68e48f8d408be83d421077a2fdbd80d064..76829eb48deceec26f3427396508910e0d6c868a 100644 (file)
@@ -40,7 +40,7 @@ const actions = [
       if (data.datasets.length > 0) {
         data.labels.push('data #' + (data.labels.length + 1));
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.rand(0, 100));
         }
 
index 4a7d11e47d9f359887d6a85f1b11d05cc546fbb5..e3f83bcd0f25a833ef1848796d4dd5ba8cc99142 100644 (file)
@@ -44,7 +44,7 @@ const config = {
             const labelsOriginal = original.call(this, chart);
 
             // Build an array of colors used in the datasets of the chart
-            var datasetColors = chart.data.datasets.map(function(e) {
+            let datasetColors = chart.data.datasets.map(function(e) {
               return e.backgroundColor;
             });
             datasetColors = datasetColors.flat();
index 3578625075e78867137b2b2f5aa58227735fe2e8..3715ad3371376e461399177676d434d0e80f8aff 100644 (file)
@@ -40,7 +40,7 @@ const actions = [
       if (data.datasets.length > 0) {
         data.labels.push('data #' + (data.labels.length + 1));
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.rand(0, 100));
         }
 
index 826a39991e4bd4caf9ce8fddff3e2d9ef583f5a8..ee7c75841452bf01997fb00a52d19a7e594af0be 100644 (file)
@@ -19,7 +19,7 @@ const actions = [
       if (data.datasets.length > 0) {
         data.labels.push('data #' + (data.labels.length + 1));
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.rand(0, 100));
         }
 
index e6fc7a890d0e58677d014426f205c010e948159b..a6bc12b572334aba1b1953c858480021a68bd2d3 100644 (file)
@@ -34,7 +34,7 @@ const actions = [
       if (data.datasets.length > 0) {
         data.labels = Utils.months({count: data.labels.length + 1});
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.rand(0, 100));
         }
 
index 9241d720d851bc76c4ae313bc32fdbf1ea28f95a..d63120d7046164e7b442da2035851015b0404dc6 100644 (file)
@@ -33,7 +33,7 @@ const actions = [
       const data = chart.data;
       if (data.datasets.length > 0) {
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.bubbles({count: 1, rmin: 1, rmax: 1, min: -100, max: 100})[0]);
         }
 
index d6690575e728500350fc8ac0f1feb48c969f04d9..c5696b93bc9e6cc5e92f5abb56fe0136f8c83426 100644 (file)
@@ -33,7 +33,7 @@ const actions = [
       const data = chart.data;
       if (data.datasets.length > 0) {
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.bubbles({count: 1, rmin: 1, rmax: 1, min: 0, max: 100})[0]);
         }
 
index 1afbbd4aaeebab90b4bb1c8a225a855d3e7b7807..8a29c7b44b215fdc82ee8277db0e174263e6d37d 100644 (file)
@@ -36,7 +36,7 @@ const actions = [
       if (data.datasets.length > 0) {
         data.labels = Utils.months({count: data.labels.length + 1});
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.rand(0, 100));
         }
 
index 049b0ae5dc65851cf258f11e4965bbc3aeaafa7c..3173ee80b0fb13caa05a3dc94a37c3ea306fe07f 100644 (file)
@@ -34,7 +34,7 @@ const actions = [
       if (data.datasets.length > 0) {
         data.labels = Utils.months({count: data.labels.length + 1});
 
-        for (var index = 0; index < data.datasets.length; ++index) {
+        for (let index = 0; index < data.datasets.length; ++index) {
           data.datasets[index].data.push(Utils.rand(0, 100));
         }
 
index 8842c6a9cc8aa79e847f02dec23ff428da3ac12c..27cd712281a08e39104951eec30ddbfcf9c317ff 100644 (file)
@@ -2,7 +2,7 @@
 
 ```js chart-editor
 // <block:setup:2>
-var DATA_COUNT = 16;
+const DATA_COUNT = 16;
 Utils.srand(110);
 
 const actions = [
@@ -38,8 +38,8 @@ const data = {
 // <block:options:0>
 function colorize(opaque) {
   return (ctx) => {
-    var v = ctx.parsed.y;
-    var c = v < -50 ? '#D60000'
+    const v = ctx.parsed.y;
+    const c = v < -50 ? '#D60000'
       : v < 0 ? '#F46300'
       : v < 50 ? '#0358B6'
       : '#44DE28';
index d466172cd75701cf6510132f675d105d91d2e42c..7ed304ac0dc275dc581d25fd1063f2415fa58886 100644 (file)
@@ -22,8 +22,8 @@ const actions = [
 
 // <block:data:1>
 function generateData() {
-  var data = [];
-  var i;
+  const data = [];
+  let i;
 
   for (i = 0; i < DATA_COUNT; ++i) {
     data.push({
@@ -51,13 +51,13 @@ function channelValue(x, y, values) {
 }
 
 function colorize(opaque, context) {
-  var value = context.raw;
-  var x = value.x / 100;
-  var y = value.y / 100;
-  var r = channelValue(x, y, [250, 150, 50, 0]);
-  var g = channelValue(x, y, [0, 50, 150, 250]);
-  var b = channelValue(x, y, [0, 150, 150, 250]);
-  var a = opaque ? 1 : 0.5 * value.v / 1000;
+  const value = context.raw;
+  const x = value.x / 100;
+  const y = value.y / 100;
+  const r = channelValue(x, y, [250, 150, 50, 0]);
+  const g = channelValue(x, y, [0, 50, 150, 250]);
+  const b = channelValue(x, y, [0, 150, 150, 250]);
+  const a = opaque ? 1 : 0.5 * value.v / 1000;
 
   return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
 }
@@ -92,8 +92,8 @@ const config = {
         },
 
         radius: function(context) {
-          var size = context.chart.width;
-          var base = Math.abs(context.raw.v) / 1000;
+          const size = context.chart.width;
+          const base = Math.abs(context.raw.v) / 1000;
           return (size / 24) * base;
         }
       }
index beeff9ed442bd1de642e37733e5d7c7700081832..9b634a8b82e711eac20d8869168ebaf70553b3be 100644 (file)
@@ -41,7 +41,7 @@ function getLineColor(ctx) {
 }
 
 function alternatePointStyles(ctx) {
-  var index = ctx.dataIndex;
+  const index = ctx.dataIndex;
   return index % 2 === 0 ? 'circle' : 'rect';
 }
 
@@ -50,7 +50,7 @@ function makeHalfAsOpaque(ctx) {
 }
 
 function adjustRadiusBasedOnData(ctx) {
-  var v = ctx.parsed.y;
+  const v = ctx.parsed.y;
   return v < 10 ? 5
     : v < 25 ? 7
     : v < 50 ? 9
index 423e213f887aab496e4af4dd0827cbd171e5dbad..c69101dcf08344ad8db5013b26dbbe8d4e98d07a 100644 (file)
@@ -47,13 +47,13 @@ const data = {
 
 // <block:options:0>
 function colorize(opaque, hover, ctx) {
-  var v = ctx.parsed;
-  var c = v < -50 ? '#D60000'
+  const v = ctx.parsed;
+  const c = v < -50 ? '#D60000'
     : v < 0 ? '#F46300'
     : v < 50 ? '#0358B6'
     : '#44DE28';
 
-  var opacity = hover ? 1 - Math.abs(v / 150) - 0.2 : 1 - Math.abs(v / 150);
+  const opacity = hover ? 1 - Math.abs(v / 150) - 0.2 : 1 - Math.abs(v / 150);
 
   return opaque ? c : Utils.transparentize(c, opacity);
 }
index 4fe6e04b9144b80f801d8bc90a5b7d3d80e92144..15f656935bccd72d54dff112070b4c3bf24aa3ce 100644 (file)
@@ -37,13 +37,13 @@ const data = {
 
 // <block:options:0>
 function colorize(opaque, hover, ctx) {
-  var v = ctx.raw;
-  var c = v < 35 ? '#D60000'
+  const v = ctx.raw;
+  const c = v < 35 ? '#D60000'
     : v < 55 ? '#F46300'
     : v < 75 ? '#0358B6'
     : '#44DE28';
 
-  var opacity = hover ? 1 - Math.abs(v / 150) - 0.2 : 1 - Math.abs(v / 150);
+  const opacity = hover ? 1 - Math.abs(v / 150) - 0.2 : 1 - Math.abs(v / 150);
 
   return opaque ? c : Utils.transparentize(c, opacity);
 }
index fc3b686b88f622d8bc1d95bddf2e61af83dbb601..53634f3300e67f3838a1b7cc77397f1f29566a4d 100644 (file)
@@ -41,7 +41,7 @@ function getLineColor(ctx) {
 }
 
 function alternatePointStyles(ctx) {
-  var index = ctx.dataIndex;
+  const index = ctx.dataIndex;
   return index % 2 === 0 ? 'circle' : 'rect';
 }
 
@@ -54,7 +54,7 @@ function make20PercentOpaque(ctx) {
 }
 
 function adjustRadiusBasedOnData(ctx) {
-  var v = ctx.parsed.y;
+  const v = ctx.parsed.y;
   return v < 10 ? 5
     : v < 25 ? 7
     : v < 50 ? 9