How to import the Chart.js library into an ASP file?

0

I'm trying to insert a chart with Chart.js into an ASP page (not ASP.NET). I saw some tutorials from Chart.js itself and found the following statement:

  

You can download the latest version of Chart.js from the GitHub releases.

     

[...]

     

Chart.js can be installed via npm or bower.

     

For npm:
npm install chart.js --save

     

[...]

     

Chart.js can be integrated with plain JavaScript or with different module loaders. The example in below show how to load Chart.js in Script mode.
<script src="path/to/chartjs/dist/Chart.js"></script> .

So I interpreted that in " src " I need to put the path of the Chart.js file that I downloaded. So I pasted this file into the Library folder of my project. The file I want to insert a graphic into is the grafico_diario.asp , contained in the project root folder. So, in this ASP file, I put it like this:

However, the graph does not appear when I test on the server. Can you tell me if I'm importing the library correctly?

    
asked by anonymous 22.06.2017 / 19:53

1 answer

0

One test you could do is grab the CDN from the chart and include it within the <head></head> tags of your page:

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.bundle.min.js"></script>

Andrunatestlikethis:

<canvasid="myChart" width="400" height="400"></canvas>
<script>
var ctx = document.getElementById("myChart");
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],
            backgroundColor: [
                'rgba(255, 99, 132, 0.2)',
                'rgba(54, 162, 235, 0.2)',
                'rgba(255, 206, 86, 0.2)',
                'rgba(75, 192, 192, 0.2)',
                'rgba(153, 102, 255, 0.2)',
                'rgba(255, 159, 64, 0.2)'
            ],
            borderColor: [
                'rgba(255,99,132,1)',
                'rgba(54, 162, 235, 1)',
                'rgba(255, 206, 86, 1)',
                'rgba(75, 192, 192, 1)',
                'rgba(153, 102, 255, 1)',
                'rgba(255, 159, 64, 1)'
            ],
            borderWidth: 1
        }]
    },
    options: {
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero:true
                }
    
22.06.2017 / 20:06