[Chartjs]-Add chart using chart.js in codeigniter

3๐Ÿ‘

โœ…

I have fixed my problem. I just changes the source on my script tag.
See the updated code below.

<div class="container">
    <h2>This is a sample โ€” Line Chart</h2>
    <div>
        <canvas id="myChart"></canvas>
    </div>
</div>

 <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js">
    var ctx = document.getElementById("myChart").getContext("2d");

    var myChart = new Chart(ctx, {
            type: 'line',
            data: {
                  labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
                  datasets: [{
                        label: '# of Votes',
                        data: [12, 19, 3, 5, 2, 3]
                             }]
                  },
            options: {
            scales: {
                  yAxes: [{
                        ticks: {
                             beginAtZero:true
                               }
                          }]
                    }
           }
       });
  </script>

-1๐Ÿ‘

you are missing script tag for your js code

<script>
var ctx = document.getElementById("myChart").getContext("2d");

var myChart = new Chart(ctx, {
    type: 'line',
    data: {
        labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
        datasets: [{
            label: '# of Votes',
            data: [12, 19, 3, 5, 2, 3]
        }]
    },
    options: {
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero:true
                }
            }]
        }
    }
});
</script>

Leave a comment