Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

javascript - 在没有npm,bower或CDN的项目中安装chartjs(Installing chartjs in project without npm, bower or CDN)

I am working on a graph page for a project and my client does not want me to use npm, bower or CDN.(我正在一个项目的图形页面上工作,我的客户不希望我使用npm,bower或CDN。)

so my question is how would I use the chartjs library without using these options?(所以我的问题是,在不使用这些选项的情况下如何使用chartjs库?) I tried using it this way:(我尝试以这种方式使用它:) var Chart = require(['../chartjs/Chart.js']); var ctx = document.getElementById("bar-chart"); 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 } }] } } }); but I keep getting the following error:(但我不断收到以下错误:) Uncaught Error: Script error for "../chartjs/Chart.js". Am I missing a step?(我错过了一步吗?)   ask by randomtardis42 translate from so

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

1 Reply

0 votes
by (71.8m points)

Try this(尝试这个)

import chart from './chart'; console.log(chart);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...