0

I am creating my control panel and liked to create a chart to show data from my table but is giving me this error. Uncaught ReferenceError: Chart is not defined I do not know much about javascript. If anyone could help me grateful.

Html

<div class="box-body no-padding">
    <canvas id="canvas" height="450" width="610"></canvas>
</div><!-- /.box-body -->

My script

<script>

    var PieChart = [
            {
                value: 40,
                color:"#fcc79e"
            },
            {
                value : 30,
                color : "#beefd2"
            },
            {
                value : 90,
                color : "#ffddfb"
            }

        ];

var myPieChart = new Chart(document.getElementById("canvas").getContext("2d")).Pie(PieChart);

            </script>   
Karl
  • 5,435
  • 11
  • 44
  • 70
Jose Cerejo
  • 231
  • 1
  • 5
  • 19

1 Answers1

1

Update your library. I have test this and working.

 <div class="box-body no-padding">
    <canvas id="canvas" height="450" width="610"></canvas>
</div>
<script src="https://raw.githubusercontent.com/nnnick/Chart.js/master/Chart.min.js" ></script>
<script>

    var PieChart = [
            {
                value: 40,
                color:"#fcc79e"
            },
            {
                value : 30,
                color : "#beefd2"
            },
            {
                value : 90,
                color : "#ffddfb"
            }

        ];

var myPieChart = new Chart(document.getElementById("canvas").getContext("2d")).Pie(PieChart);

            </script> 
Farhan
  • 1,453
  • 2
  • 15
  • 20
  • I'm building the site in laravel and it gives me this error Refused to execute script from 'https://raw.githubusercontent.com/nnnick/Chart.js/master/Chart.min.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled. – Jose Cerejo Dec 15 '15 at 19:17
  • check this http://stackoverflow.com/questions/24528211/refused-to-execute-script-from-because-its-mime-type-application-json-is – Farhan Dec 15 '15 at 19:22
  • how to do it in yii2? can you please see my related [question](https://stackoverflow.com/questions/61255144/yii2-chart-is-not-defined)? – Moeez Apr 16 '20 at 16:53