如何确定我是否正确实现了d3? [英] How to determine if i have implemented d3 correctly?

查看:116
本文介绍了如何确定我是否正确实现了d3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原谅我这个初学者的问题。我试图在HTML页面上实现d3,它显示在Swing项目中的JScrollPane中。遵循教程@ http://alignedleft.com/tutorials/d3/adding-elements



在输入代码时,我在每个点后看不到模板提案。现在不想在临时服务器上运行它。我运行应用程序时应该生成的新段不会出现。



这是否意味着我的源链接到d3是错误实现,因此没有模板建议?有没有什么方法来确定是否来自DOM的元素是否被正确选择?未嵌入在脚本中的元素会正确显示。请指教。



代码:

 <!DOCTYPE html> 
< html lang =en>
< head>
< meta charset =utf-8>
< title> D3 test< / title>
< script type =text / javascriptsrc =d3 / d3.v3.js>< / script>
< / head>

< body>
< script type =text / javascriptsrc =d3.js>
d3.select(body)。append(p)。text(New paragraph !!!);
< / script>

< / body>
< / html>

其他类:

  jfxpanel = new JFXPanel(); 
Platform.runLater(new Runnable(){
@Override
public void run(){
try {
WebView browser = new WebView();
WebEngine engine = browser.getEngine();
//字符串url =http://www.hotmail.com;

文件f =新文件(src / d3 / index.html); //显示本地html,而不是外部网页
System.out.println(current directory:+ f.getAbsolutePath());
String url = f.toURI ).toURL()。toString();
engine.load(url);

场景scene = new Scene(browser);
jfxpanel.setScene b $ b}
catch(Exception e){
while(e!= null){
e.printStackTrace();
}
}
}
});

spVisual = new JScrollPane(jfxpanel);
//spVisual.setEnabled(false);
spVisual.setViewportBorder(new EtchedBorder(EtchedBorder.LOWERED,null,null));
spVisual.setSize(800,420);
spVisual.setLocation(100,140);
spVisual.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_​​AS_NEEDED);
//spVisual.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_​​AS_NEEDED);
spVisual.setHorizo​​ntalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_​​AS_NEEDED);
SwingUtilities.invokeLater(new Runnable(){
public void run(){
spVisual.getViewport()。setViewPosition(new java.awt.Point(0,0));
}
});

add(spVisual);


解决方案

不知道如何在swing中嵌入html我知道,在同一个标记上使用 src 和内嵌JavaScript不是好主意



此外, TEST < script>



最后,假设 d3 / code>正在加载,您的选择器,附加和文字都可以。



也许尝试:

 <!DOCTYPE html> 
< html lang =en>
< head>
< meta charset =utf-8>
< title> D3 test< / title>
< script src =d3 / d3.v3.js>< / script>
< / head>

< body>
< script>
d3.select(body)。append(p)。text(New paragraph !!!);
< / script>
TEST
< / body>
< / html>


Forgive me for this beginner question. I am trying to implement d3 on a HTML page, which is displayed in a JScrollPane in a Swing project. Am following the tutorial @ http://alignedleft.com/tutorials/d3/adding-elements.

As I type code, I do not see template proposals after every dot. Would not like to run it on a temp server at the moment. The new paragraph that's supposedly generated when I run the application does not appear.

Does that mean that my source link to d3 is implemented wrongly & hence no template proposals? Is there any way to determine if elements from the DOM are selected correctly? Elements not embedded within the script is shown correctly however. Please advise.

Code:

<!DOCTYPE html>
<html lang = "en">
    <head>
        <meta charset="utf-8">
        <title>D3 test</title>
        <script type = "text / javascript" src="d3/d3.v3.js"></script>
    </head>

    <body>
        <script type = "text / javascript" src="d3.js">
            d3.select("body").append("p").text("New paragraph!!!");
        </script>

    </body>
</html>

the other class:

        jfxpanel = new JFXPanel();      
        Platform.runLater(new Runnable() {
            @Override
            public void run() {             
                try {
                    WebView browser = new WebView();
                    WebEngine engine = browser.getEngine();
                    //String url = "http://www.hotmail.com";

                    File f = new File ("src/d3/index.html");    //display local html, instead of external webpage
                    System.out.println("current directory: " + f.getAbsolutePath());
                    String url = f.toURI().toURL().toString();
                    engine.load(url);

                    Scene scene = new Scene(browser);
                    jfxpanel.setScene(scene);
                }
                catch (Exception e){
                    while (e != null) {
                        e.printStackTrace();
                    }
                }
            }
        });

        spVisual = new JScrollPane(jfxpanel);
        //spVisual.setEnabled(false);
        spVisual.setViewportBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
        spVisual.setSize(800, 420);
        spVisual.setLocation(100, 140);
        spVisual.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        //spVisual.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        spVisual.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                  spVisual.getViewport().setViewPosition(new java.awt.Point(0, 0));
              }
        }); 

        add (spVisual); 

解决方案

Don't know anything about embedding html in swing but I do know that, using src and inline javascript on the same tag is not a good idea.

Also that TEST is within a <script> tag, so it'll be executed as javascript and it's not valid.

Finally, you assuming d3 is loading, your selector, append and text are fine.

Perhaps try:

<!DOCTYPE html>
<html lang = "en">
    <head>
        <meta charset="utf-8">
        <title>D3 test</title>
        <script src="d3/d3.v3.js"></script>
    </head>

    <body>
        <script>
            d3.select("body").append("p").text("New paragraph!!!");                
        </script>
        TEST
    </body>
</html>

这篇关于如何确定我是否正确实现了d3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆