Henning
Henning

Reputation: 15

Chart.js runs in JSFiddle but not local "Chart is not defined"

I started to develop my first Website. When I try to implement chart.js in Brackets, I always get "ReferenceError: "Chart is not defined" in my Firefox-console. If I copy it in JSFiddle, it works. Thanks for help!

<head> 
</head>

<body>
<script src="js/jquery.js"></script>`
<script scr="Chart.min.js"> </script>  `

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

<script>

var data = {
labels : ["January","February","March","April","May","June","July"],
datasets : [
    {
        fillColor : "rgba(220,220,220,0.5)",
        strokeColor : "rgba(220,220,220,1)",
        data : [65,59,90,81,56,55,40]
    },
    {
        fillColor : "rgba(151,187,205,0.5)",
        strokeColor : "rgba(151,187,205,1)",
        data : [28,48,40,19,96,27,100]
    }
   ]
   }


var ctx = $("#canvas")[0].getContext("2d");
var TestChart = new Chart(ctx).Bar(data);
new Chart(ctx).Bar(data);

</script>
</body>

Upvotes: 0

Views: 864

Answers (1)

Hardy
Hardy

Reputation: 5631

You have typo in your code:

<script scr="Chart.min.js"></script> 

should be:

<script src="Chart.min.js"></script> 

Try to change your code like this:

<html>
<head>
  <script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js">
  </script>
</head>

<body>
  `

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

  <script>
    var data = {
      labels: ["January", "February", "March", "April", "May", "June", "July"],
      datasets: [{
        fillColor: "rgba(220,220,220,0.5)",
        strokeColor: "rgba(220,220,220,1)",
        data: [65, 59, 90, 81, 56, 55, 40]
      }, {
        fillColor: "rgba(151,187,205,0.5)",
        strokeColor: "rgba(151,187,205,1)",
        data: [28, 48, 40, 19, 96, 27, 100]
      }]
    }


    var ctx = $("#canvas")[0].getContext("2d");
    var TestChart = new Chart(ctx).Bar(data);
    new Chart(ctx).Bar(data);
  </script>
</body>
</html>

Upvotes: 1

Related Questions