Chart.js Example Code not working

1πŸ‘

βœ…

The syntax is different if you are using Chart.js v1 or v2.

You imported the v1 library using <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script>.

But you actually used the v2 syntax :

var myChart = new Chart(ctx, {
    type: 'line',
    data: {
        // ...
    }
});

To fix this, you can either :

  • Change the syntax to the v1’s :

    var myChart= new Chart(ctx).Line({
        labels: ['M', 'T', 'W', 'T', 'F', 'S', 'S'],
        datasets: [{
                // ...
            }]
        });
    
  • (I suggest this option) Change your imported library to the latest one using :

    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.min.js"></script>
    

πŸ‘:1

include bundle.min.js
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.bundle.min.js"></script>
example with your code https://jsfiddle.net/sv4snt39/1/

Leave a comment