        },
        scales: isSingleValueType() ? {} : {
          x: { grid: { color: gridColor }, ticks: { color: textColor } },
          y: { grid: { color: gridColor }, ticks: { color: textColor } },
        },
      };

      return { type: state.chartType, data, options, plugins: [canvasBgPlugin] };
    }

    function ensureChart() {
      const ctx = document.getElementById('chart').getContext('2d');
      if (chart) chart.destroy();
      const cfg = buildChartConfig();
      chart = new Chart(ctx,