I am developing an application which shows the data created in a chartjs 
graph, what I am doing it does well, since all the data is displayed in the 
way I want, but I have a problem and that is that now I am trying to do 
that according to the type of graph that a user wants, this is changed, the 
problem is that the graph is changed but in case of having multiple graphs 
only the first graph is changed, the others continue with the graph by 
default.
<canvas id="{{ project.slug }}" width="400" height="400"></canvas>

<script type="text/javascript">
    var faltante = 100 - {{ project.porcent }};

    var data = {
        labels: ['{{ project.name }}', 'Falta'],
        datasets: [{
            data: [{{ project.porcent }}, faltante],
            backgroundColor: ['#252850', '#f44611'],
        }],
    };

    var ctx = document.getElementById('{{ project.slug }}').getContext('2d');
    var myChart = new Chart(ctx, {
        type: 'pie',
        data: data
    });
    
    var chartType = document.getElementById('chartType');
    
    chartType.addEventListener('change', () => {
        myChart.destroy();
        myChart = new Chart(ctx, {
            type: chartType.value,
            data: data
        });
    });
</script>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b7a7fa52-9e2d-477e-b3df-708ccd22cdbdn%40googlegroups.com.

Reply via email to