Thank you for the info. We edited the buttons and added a new data-destination attribute containing the name of the destination. We then added this script to reset and update the chart after clicking the destination buttons. You can find the test page in the secure note.
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('.x-button-dest').forEach(button => {
button.addEventListener('click', function() {
const destination = this.getAttribute('data-destination');
const capitalizedDestination = destination.charAt(0).toUpperCase() + destination.slice(1);
console.log('pie-' + capitalizedDestination);
const canvas = document.getElementById('pie-' + capitalizedDestination);
console.log(canvas)
if (!canvas) return;
const chartConfig = JSON.parse(canvas.getAttribute('data-tco-chart'));
const existingChart = window.Chartjs.getChart(canvas);
console.log(existingChart)
if (existingChart) {
existingChart.reset();
existingChart.update();
}
const ctx = canvas.getContext('2d');
// const newChart = new window.Chartjs(ctx, chartConfig);
// canvas.$chartjs = newChart;
});
});
});
Result: https://streamable.com/wpop55