使用 require.js 加载 Highcharts
一段时间以来,我一直在尝试将 highcharts 作为 require 模块加载,但收效甚微。我想知道是否有人设法让这个工作正常进行,或者他们是否有任何指示让我走上正确的轨道?
谢谢
I have been trying for some time with little success to be able to load highcharts as a require module. I was wondering if anyone had managed to get this working, or if they had any pointers to get me on the right track?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 require.js 2.1.0+ 不需要插件。您可以使用 shim 包含 Highcharts:
With require.js 2.1.0+ a plugin is not necessary. You can include Highcharts with a shim:
我刚刚让它按如下方式工作:
将其添加到顶部:
在最后添加此内容:
返回窗口.Highcharts; });
这假设您已经定义了 jquery,例如,
您可以对大多数第三方库遵循这种通用方法。例如,我对 jquery.tmpl.js 和 knockout.js 执行了此操作。
I just got it to work as follows:
Add this at the top:
Add this at the very end:
return window.Highcharts; });
This assumes you have jquery already defined, eg
You can follow this general approach for most third party libraries. For example, I did this for jquery.tmpl.js and knockout.js.
使用最近的 use.js 插件 绝对是最佳选择。按照我之前的回答中的建议编辑第三方库对于可维护性来说是一个痛苦。
Using the recent use.js plugin is definitely the way to go. Editing third party libs as suggested in my previous answer is a pain for maintainability.
最近使用模块的 Highcharts 方法的最小示例(JSFiddle 示例):
请参阅 此 Highcharts 文档 了解使用说明。
A minimal example of a recent approach for Highcharts with a module (JSFiddle example):
See this Highcharts documentation for a usage description.