Skip to content

Commit 67c5a85

Browse files
authored
Define with let to avoid "assignment to constant" errors (#9803)
* Define with let to avoid "assignment to constant" errors Thanks for this example. Defining `label` with `const` rather than `let` results in `Uncaught TypeError: Assignment to constant variable.` * Another case where const needs to be replaced with let. * Requested cases where const needs to be replaced with let +1 (style).
1 parent 1749e57 commit 67c5a85

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

docs/configuration/tooltip.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Namespace: `options.plugins.tooltip`, the global options for the chart tooltips is defined in `Chart.defaults.plugins.tooltip`.
66

77
:::warning
8-
The bubble, doughnut, pie, polar area, and scatter charts override the tooltip defaults. To change the overrides for those chart types, the options are defined in `Chart.overrides[type].plugins.tooltip`.
8+
The bubble, doughnut, pie, polar area, and scatter charts override the tooltip defaults. To change the overrides for those chart types, the options are defined in `Chart.overrides[type].plugins.tooltip`.
99
:::
1010

1111
| Name | Type | Default | Description
@@ -157,7 +157,7 @@ const chart = new Chart(ctx, {
157157
tooltip: {
158158
callbacks: {
159159
label: function(context) {
160-
const label = context.dataset.label || '';
160+
let label = context.dataset.label || '';
161161

162162
if (label) {
163163
label += ': ';
@@ -282,7 +282,7 @@ const myPieChart = new Chart(ctx, {
282282

283283
external: function(context) {
284284
// Tooltip Element
285-
const tooltipEl = document.getElementById('chartjs-tooltip');
285+
let tooltipEl = document.getElementById('chartjs-tooltip');
286286

287287
// Create element on first render
288288
if (!tooltipEl) {
@@ -316,7 +316,7 @@ const myPieChart = new Chart(ctx, {
316316
const titleLines = tooltipModel.title || [];
317317
const bodyLines = tooltipModel.body.map(getBody);
318318

319-
const innerHtml = '<thead>';
319+
let innerHtml = '<thead>';
320320

321321
titleLines.forEach(function(title) {
322322
innerHtml += '<tr><th>' + title + '</th></tr>';
@@ -325,15 +325,15 @@ const myPieChart = new Chart(ctx, {
325325

326326
bodyLines.forEach(function(body, i) {
327327
const colors = tooltipModel.labelColors[i];
328-
const style = 'background:' + colors.backgroundColor;
328+
let style = 'background:' + colors.backgroundColor;
329329
style += '; border-color:' + colors.borderColor;
330330
style += '; border-width: 2px';
331331
const span = '<span style="' + style + '"></span>';
332332
innerHtml += '<tr><td>' + span + body + '</td></tr>';
333333
});
334334
innerHtml += '</tbody>';
335335

336-
const tableRoot = tooltipEl.querySelector('table');
336+
let tableRoot = tooltipEl.querySelector('table');
337337
tableRoot.innerHTML = innerHtml;
338338
}
339339

docs/developers/updates.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ Variables referencing any one from `chart.scales` would be lost after updating s
6666

6767
```javascript
6868
function updateScales(chart) {
69-
const xScale = chart.scales.x;
70-
const yScale = chart.scales.y;
69+
let xScale = chart.scales.x;
70+
let yScale = chart.scales.y;
7171
chart.options.scales = {
7272
newId: {
7373
display: true

0 commit comments

Comments
 (0)