Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
957 views
in Technique[技术] by (71.8m points)

javascript - Uncaught ReferenceError: Chart is not defined at test.html:11

I'm completing my cs50 final project so am coding in the cs50 ide. I am trying to create a graph using chart.js so am using the test code they provide to try and get it to work on my website. However I am getting the error written in the title when I'm on my server. I have tried putting the JavaScript code in a separate file but that does not work either. Any ideas as to what i am doing wrong?

Here is my code

<!DOCTYPE html>
<html lang="en">
    <head>
        <script scr="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js"></script>
        <title> Chart</title>
    </head>
    <body>
        <canvas id="myChart" width="400" height="400"></canvas>
        <script>
            var ctx = document.getElementById('myChart').getContext('2d');
            var myChart = new Chart(ctx, {
                type: 'bar',
                data: {
                    labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
                    datasets: [{
                        label: '# of Votes',
                        data: [12, 19, 3, 5, 2, 3],}]
                }});
        </script>
    </body>
</html>
question from:https://stackoverflow.com/questions/65832071/uncaught-referenceerror-chart-is-not-defined-at-test-html11

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have a typo in your chart JS script inclusion. You have done scr and not src.

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js"></script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...