$wnd.google.visualization 未定义
我目前正在构建一个基于 SmartGWT 的 Web 应用程序(使用 Portlet 布局)。所以我有几个“Portlet”,它们基本上用不同的内容扩展了GWT Window。现在我想要一个 Portlet 来显示 Dygraphs。因此,我创建了一个 RPC 服务实现,它返回一个 JSON 字符串(基于 DataTable 对象)。
由于我无法直接序列化 DataTable 对象,因此我
String json = JsonRenderer.renderDataTable(data, true, true).toString();
在“数据”为 DataTable 类型的情况下使用。
现在这个字符串已正确传递到我想要创建 Dygraph 的客户端。在此线程中,有人建议使用
public static native DataTable toDataTable(String json)
/-{ return new $wnd.google.visualization.DataTable(eval("(" + json + ")")); }-/;
如果我在我的GWT客户端代码中使用它,我收到一条错误消息,提示
com.google.gwt.core.client.JavaScriptException: (TypeError): $wnd.google.visualization is undefined
我是否错过了可视化 API 的某些“导入”?我必须在哪里实例化它?
或者还有其他方法将 JSON 数据字符串输入 Dygraph 中吗?我找不到任何例子...
谢谢您的任何提示!
I'm currently building a SmartGWT-based web application (using the Portlet Layout). So I have several "Portlet", which basically extend GWT Window with different content. Now I want a Portlet to display Dygraphs. So I've created an RPC Service implementation which returns a JSON String (based on a DataTable object).
Since I cannot directly serialize a DataTable object I use
String json = JsonRenderer.renderDataTable(data, true, true).toString();
where "data" is of type DataTable.
Now this String gets correctly passed to the client side where I want to create the Dygraph. In this thread , someone suggested to use
public static native DataTable toDataTable(String json)
/-{ return new $wnd.google.visualization.DataTable(eval("(" + json + ")")); }-/;
If I use this in my GWT client code, i get an error saying
com.google.gwt.core.client.JavaScriptException: (TypeError): $wnd.google.visualization is undefined
Do i miss some "import" of the visualization API? Where do i have to instantiate it?
Or is there another way to get the JSON datastring into the Dygraph? I can't find any examples...
Thank you for any hint!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您已将 Visualization.jar 和可视化命名空间包含在模块的 XML 中,
这将为您提供类。您可能已经这样做了,否则您会收到编译器错误。
但是,您还必须包含来自 google 服务器的实际可视化 javascript 文件(visualization.jar 只是一个包装器)。这可以通过两种不同的方式完成:
1.) 将其包含在主页中:
或
2.) 在需要的地方动态加载它:
请参阅 http://code.google.com/docreader/#p=gwt-google-apis&s= gwt-google-apis&t=VisualizationGettingStarted
顺便说一句。我已经分叉了 Dygraphs 项目,并将 GWT 包装器更改为更像其他可视化包装器。您可以在这里查看:https://github.com/timeu/dygraphs
编辑: 我有一个新的 dygraphs GWT 包装器,它使用 GWT 2.8 的新 JsInterop: https ://github.com/timeu/dygraphs-gwt
注意:我更改了 dygraphs 中的一些行为,并添加了一些上游代码中不可用的功能。
I assume you have included the visualization.jar and the visualization namespace in your module's XML
This will give you the Classes. You probably have done this otherwise you would have gotten a compiler error.
However you also have to include the actual visualization javascript file from the google servers (the visualization.jar is only a wrapper). This can be done in two different ways:
1.) Include it in the host page:
or
2.) Load it dynamically where you need it:
see http://code.google.com/docreader/#p=gwt-google-apis&s=gwt-google-apis&t=VisualizationGettingStarted
Btw. I have forked the Dygraphs Project and changed the GWT wrapper to more like the other visualization wrappers. You can check it out here: https://github.com/timeu/dygraphs
Edit: I have a new GWT wrapper for dygraphs that uses the GWT 2.8's new JsInterop: https://github.com/timeu/dygraphs-gwt
Note: I changed some behaviour in dygraphs and added some features which weren't available in the upstream code.