ddEventListener('change', (e) => {
      state.chartType = e.target.value;
      updateVisibilityByType();
      ensureChart();
    });
    $('#labelColumn').addEventListener('change', (e) => {
      state.labelColumn = parseInt(e.target.value, 10) || 0;
      state.datasets = state.datasets.filter(c => c !== state.labelColumn);
      rebuildColumnSelectors();
      ensureChart();
    });
    $('#valueColumn').addEventListener('change', (e) => {
      state.valueColumn = parseInt(e.target.value, 10) || 1;
 