Construct a bar chart using chart.js

1๐Ÿ‘

โœ…

Try this code:
Html:

<canvas id="canvas" width="256" height="256"></canvas>

Js:

 var chr = document.getElementById("canvas");
    var ctx = canvas.getContext("2d");
    var data = {
      type: "bar",
      data: {
        labels: ["One", "Two"],
        datasets: [{
          label: "my first dataset",
          backgroundColor: ["#F7464A", "#46BFBD", "#FDB45C"],
          fillColor: "blue",
          strokeColor: "green",
          data: [65, 53]
        }]
      }
    };
    var myfirstChart = new Chart(ctx, data);

๐Ÿ‘:0

Joseph i have made some correction in script as following. its working fine try this.

<script>
      var chr = document.getElementById("canvas");      
      var ctx = chr.getContext("2d");    	
	    ctx.canvas.width = 800;
	    var data = {
      type: "bar",
      data: {
        labels: ["One", "Two"],
        datasets: [{
          label: "my first dataset",
          backgroundColor: ["#F7464A", "#46BFBD", "#FDB45C"],
          fillColor: "blue",
          strokeColor: "green",
          data: [65, 53]
        }]
      }
    };
            
        
    var myfirstChart = new Chart(chr , data);
    </script>   

Leave a comment