mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 12:19:08 +02:00
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).
This commit is contained in:
parent
1749e57918
commit
67c5a85144
@ -157,7 +157,7 @@ const chart = new Chart(ctx, {
|
||||
tooltip: {
|
||||
callbacks: {
|
||||
label: function(context) {
|
||||
const label = context.dataset.label || '';
|
||||
let label = context.dataset.label || '';
|
||||
|
||||
if (label) {
|
||||
label += ': ';
|
||||
@ -282,7 +282,7 @@ const myPieChart = new Chart(ctx, {
|
||||
|
||||
external: function(context) {
|
||||
// Tooltip Element
|
||||
const tooltipEl = document.getElementById('chartjs-tooltip');
|
||||
let tooltipEl = document.getElementById('chartjs-tooltip');
|
||||
|
||||
// Create element on first render
|
||||
if (!tooltipEl) {
|
||||
@ -316,7 +316,7 @@ const myPieChart = new Chart(ctx, {
|
||||
const titleLines = tooltipModel.title || [];
|
||||
const bodyLines = tooltipModel.body.map(getBody);
|
||||
|
||||
const innerHtml = '<thead>';
|
||||
let innerHtml = '<thead>';
|
||||
|
||||
titleLines.forEach(function(title) {
|
||||
innerHtml += '<tr><th>' + title + '</th></tr>';
|
||||
@ -325,7 +325,7 @@ const myPieChart = new Chart(ctx, {
|
||||
|
||||
bodyLines.forEach(function(body, i) {
|
||||
const colors = tooltipModel.labelColors[i];
|
||||
const style = 'background:' + colors.backgroundColor;
|
||||
let style = 'background:' + colors.backgroundColor;
|
||||
style += '; border-color:' + colors.borderColor;
|
||||
style += '; border-width: 2px';
|
||||
const span = '<span style="' + style + '"></span>';
|
||||
@ -333,7 +333,7 @@ const myPieChart = new Chart(ctx, {
|
||||
});
|
||||
innerHtml += '</tbody>';
|
||||
|
||||
const tableRoot = tooltipEl.querySelector('table');
|
||||
let tableRoot = tooltipEl.querySelector('table');
|
||||
tableRoot.innerHTML = innerHtml;
|
||||
}
|
||||
|
||||
|
@ -66,8 +66,8 @@ Variables referencing any one from `chart.scales` would be lost after updating s
|
||||
|
||||
```javascript
|
||||
function updateScales(chart) {
|
||||
const xScale = chart.scales.x;
|
||||
const yScale = chart.scales.y;
|
||||
let xScale = chart.scales.x;
|
||||
let yScale = chart.scales.y;
|
||||
chart.options.scales = {
|
||||
newId: {
|
||||
display: true
|
||||
|
Loading…
Reference in New Issue
Block a user