简体   繁体   English

如何将d3(javascript)添加到vaadin应用程序?

[英]How to add d3 (javascript) to a vaadin application?

Good evening guys, 晚上好,

I'm currently trying to add the visualization functionality of d3 to my vaadin application. 我目前正在尝试将d3的可视化功能添加到我的vaadin应用程序中。 If you don't know what d3 is, here is a quick link: http://d3js.org/ 如果你不知道d3是什么,这里有一个快速链接: http//d3js.org/

Yet I am stuck with some problems: 但我遇到了一些问题:

  • How can I add the "d3.v2.js" javascript file/library, that is necessary for developing with d3? 如何添加“d3.v2.js”javascript文件/库,这是使用d3进行开发所必需的? I tried adding it to an own theme (WebContent/VAADIN/themes/myOwnTheme/..), but through refreshing in eclipse I'm getting the message: "Errors occurred during the build. Errors running builder 'JavaScript Validator' on project 'VaadinD3Testproject'. 14". 我尝试将它添加到一个自己的主题(WebContent / VAADIN / themes / myOwnTheme / ..),但是通过在eclipse中刷新,我收到消息:“在构建期间发生错误。错误运行构建器'JavaScript Validator'在项目上' VaadinD3Testproject'。14“。 I guess that's because the js-file might be too large with around 8000 lines ? 我猜那是因为js文件可能太大了,大约有8000行? I read about somehow adding the file to the web.xml? 我读到了以某种方式将文件添加到web.xml? Is there a way? 有办法吗?

  • How can I then add javascript code to my vaadin application? 我怎样才能将javascript代码添加到我的vaadin应用程序中? After my research I know that there are the options to use: 经过我的研究,我知道可以使用的选项:

    • getMainWindow().executeJavaScript("alert('foo');") 。getMainWindow()executeJavaScript( “警报( '富');”)

    or 要么

    • Label test = new Label("move mouse over here.. 标签测试=新标签(“将鼠标移到这里..

      ",Label.CONTENT_XHTML); ”,Label.CONTENT_XHTML);

--> Are there any other ways to integrate javascript code ? - >有没有其他方法来集成JavaScript代码?

Could someone help me with an kind of "step by step" explanation, how to solve both ways? 有人可以通过一种“一步一步”的解释帮助我,如何解决这两种方式? Help would really be appreciated here, since I'm not that experienced with this. 这里的帮助真的很值得赞赏,因为我对此并不熟悉。

------- UPDATE ----------- -------更新-----------

How can I add the "d3.v2.js" javascript file/library, that is necessary for developing with d3? 如何添加“d3.v2.js”javascript文件/库,这是使用d3进行开发所必需的? I tried adding it to an own theme (WebContent/VAADIN/themes/myOwnTheme/..), but through refreshing I'm getting the message: "Errors occurred during the build. Errors running builder 'JavaScript Validator' on project 'VaadinD3Testproject'. 14". 我尝试将其添加到自己的主题(WebContent / VAADIN / themes / myOwnTheme / ..),但通过刷新我收到消息:“构建期间发生错误。错误运行构建器'JavaScript Validator'项目'VaadinD3Testproject' .14“。 I guess that's because the js-file might be too large with around 8000 lines ? 我猜那是因为js文件可能太大了,大约有8000行? I read about somehow adding the file to the web.xml? 我读到了以某种方式将文件添加到web.xml? Is there a way? 有办法吗?

I fixed this error appearing, it was a problem with my eclipse and the inbuild javascript validator. 我修复了这个错误,这是我的eclipse和inbuild javascript验证器的问题。 I was now able to load the js-file into my application by overwriting the ajax class with an own servlet, as it has been described here in several posts. 我现在能够通过用自己的servlet覆盖ajax类来将js文件加载到我的应用程序中,正如在几篇文章中所描述的那样。

I have now tried several ways: 我现在尝试了几种方法:

  • getMainWindow.executeJavaScript() doesn't work in a way that I could use d3 with, somehow as soon as I want to add some d3 code, like "d3.select("body") .append("svg");", it just doesn't execute it (no matter if I do the tags around or not, but I noticed in general that code in tags wont get executed) getMainWindow.executeJavaScript()无法以某种方式使用d3,只要我想添加一些d3代码,比如“d3.select(”body“)。append(”svg“);” ,它只是不执行它(无论我是否执行标记,但我一般都注意到标记中的代码不会被执行)

  • I tried using a CustimLayout, as it has been shown in some examples of this forum, but it's again like described above. 我尝试使用CustimLayout,因为它已在本论坛的一些示例中显示,但它再次如上所述。 When I check the websites sourcecode my code is simply missing or parsed out 当我检查网站源代码时,我的代码只是丢失或解析出来

  • Labels wont work anymore, no matter if XHTML or RAW mode, exception occures 标签不再起作用,无论是XHTML还是RAW模式,都会发生异常

  • Overwriting another servlet method that is called when the bodys is built at server start, the result was that I got an error message that vaadin couldn't even load the default widgetset anymore. 覆盖在服务器启动时构建bodys时调用的另一个servlet方法,结果是我收到一条错误消息,即vaadin甚至无法加载默认的widgetset。

So, what's left? 那么,还剩下什么? Is there really no way to integrate d3 with vaadin? 有没有办法将d3与vaadin集成? Did never anyone try this? 没有人试过这个吗? I read a lot also yesterday about the upcoming vaadin 7. But would it even be kind of an option to use an alpha version from which I have no idea about its stability (I guess that's why it's called alpha ) 我昨天也读了很多关于即将推出的vaadin 7.但是它甚至可以选择使用我不知道它的稳定性的alpha版本(我猜这就是为什么它被称为alpha)

Thanks for every thought you're sharing with me 感谢您与我分享的每一个想法

The most comprehensive way to incorporate an existing javascript library is develop your own custom component . 合并现有JavaScript库的最全面的方法是开发自己的自定义组件 This is a little more involved than "normal" Vaadin development, but will give you full access to javascript methods and objects (via GWT) in the browser. 一个小比“正常” Vaadin开发更复杂的,但会给你完全访问浏览器的JavaScript方法和对象(通过GWT)。

To just include an external javascript file into the page, extend the ApplicationServlet class, and override the writeAjaxPageHtmlVaadinScripts method. 要在页面中包含外部javascript文件,请扩展ApplicationServlet类,并覆盖writeAjaxPageHtmlVaadinScripts方法。 Here is an extract from a current project that includes some external libraries. 以下是包含一些外部库的当前项目的摘录。

You can then utilise those libraries using 'getMainWindow().executeJavaScript(blah)' 然后,您可以使用'getMainWindow()。executeJavaScript(blah)'来利用这些库。

Still, from what I can see of d3 it makes more sense to develop a custom Vaadin component. 不过,从我所看到的d3来看,开发自定义Vaadin组件更有意义。 You might find it more prudent to see if there is an existing GWT d3 widget, and then try and utilise that in a Vaadin component. 您可能会发现查看是否存在现有GWT d3小部件更为谨慎,然后尝试在Vaadin组件中使用它。

@Override
protected void writeAjaxPageHtmlVaadinScripts(Window window,
                                              String themeName, Application application, BufferedWriter page,
                                              String appUrl, String themeUri, String appId,
                                              HttpServletRequest request) throws ServletException, IOException {
  page.write("<script type=\"text/javascript\">\n");
  page.write("//<![CDATA[\n");
  page.write("document.write(\"<script language='javascript' src='" + appUrl + "/VAADIN/scripts/jquery/jquery-1.4.4.min.js'><\\/script>\");\n");
  page.write("document.write(\"<script language='javascript' src='" + appUrl + "/VAADIN/scripts/highcharts/highcharts.js'><\\/script>\");\n");
  page.write("document.write(\"<script language='javascript' src='" + appUrl + "/VAADIN/scripts/highcharts/modules/exporting.js'><\\/script>\");\n");
  page.write("//]]>\n</script>\n");
  super.writeAjaxPageHtmlVaadinScripts(window, themeName, application,
      page, appUrl, themeUri, appId, request);
}

I know its too late but i started with integration of D3js and Vaadin . 我知道它为时已晚,但我开始整合D3js和Vaadin。 I got some resources . 我有一些资源。 It might help someone who is on this track First of all Best book out there for Vaadin is Book Of Vaadin This book will help you get the thorough knowledge of Vaadin Also it has been recommended for Vaadin certification 它可能对这条轨道上的人有所帮助首先为Vaadin 出版的最佳书是Vaadin书这本书将帮助您获得Vaadin的全面知识。它也被推荐用于Vaadin认证

Click Here to download Book Of Vaadin 点击这里下载 Book of Vaadin

1) Freecode Charts And D3 Wrapper 1) Freecode Charts和D3 Wrapper

2) Integration of D3 with Vaadin 2) D3与Vaadin的整合

If You get any error in this tutorial try to refer this link --> Vaadin forum 如果您在本教程中遇到任何错误,请尝试参考此链接 - > Vaadin论坛

3) Direct use of d3 libraray 3) 直接使用d3 libraray

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM