使用Rail 7中的ImportMaps的Chart.js
正在尝试将ChartJS
与Rails 7中的
我
bin/importmap pin "chart.js@^3.8.0" --download
ImportMaps
import 'chart.js'
集成对于ES模块,
Get http://localhost:5000/_/e09df68b.js` net::ERR_ABORTED 404 (Not Found) chart.js-67657cw24cb.js:1
我缺少某些内容,或者还无法整合图表。JS与Rails 7
I am trying to integrate chartjs
with importmaps in rails 7 but its not working
I have tried with following procedure
bin/importmap pin "chart.js@^3.8.0" --download
here is my application.js
import 'chart.js'
I am getting following error in chrome console and I believe it has something to do with ES modules
Get http://localhost:5000/_/e09df68b.js` net::ERR_ABORTED 404 (Not Found) chart.js-67657cw24cb.js:1
Am I missing something or its not possible yet to integrate chart.js with rails 7
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我能够通过从CDN获取图书馆而不是下载它来解决此问题。为此,我首先取消了下载的版本:
然后我将其重新固定而不下载:
现在它可以使用!
I was able to solve this by fetching the library from the CDN rather than downloading it. To do this, I first unpinned the downloaded version:
and then I repinned it without downloading:
And now it works!
截至2023年8月,在
importMap
在config/importmap.rb中,add:
以及在app/javascript/application.js中,添加:
As of August 2023, the setup for Chartkick (which uses chart.js) with Importmap is described in the Chartkick documentation, which worked for me.
Importmap
In config/importmap.rb, add:
And in app/javascript/application.js, add:
手动下载和固定来自JSDELIVR.com的软件包为我工作。
下载curl中的供应商/javaScript:
手动将图表中的导入语句更改为:js.js文件中:
手动将销钉添加到您的
config/importmap.rb
:现在,您只需遵循官方Chart.js文档即可。下面的一个工作示例。
添加到您的视图中:
添加到刺激控制器中:
Manually downloading and pinning the packages from jsdelivr.com worked for me.
Download with curl into vendor/javascript:
Manually change the import statement in the chart.js.js file to:
Manually add pins to your
config/importmap.rb
:Now you can just follow the official chart.js documentation. A working example below.
Add to your view:
Add to your Stimulus controller: