2015-02-11 121 views
1

原諒我這個初學者問題。我試圖在HTML頁面上實現d3,該頁面顯示在Swing項目的JScrollPane中。我遵循教程@http://alignedleft.com/tutorials/d3/adding-elements如何確定我是否已經正確實施了d3?

當我輸入代碼時,我沒有在每個點後看到模板提議。現在不想在臨時服務器上運行它。沒有出現我在運行應用程序時生成的新段落。

這是否意味着我的源鏈接到D3是錯誤地執行&因此沒有模板建議?有什麼方法可以確定DOM中的元素是否被正確選擇?但是,未嵌入腳本中的元素正確顯示。請指教。

代碼:

<!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> 

其他類:

 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); 
+0

通過Swing和'JScrollPane'其實際繪製組件你指的是,'JEditorPane'?請注意,沒有Swing'HTML aware'組件會對JS起作用。 – 2015-02-11 22:54:09

+0

謝謝。我的意思是我把一個jfxpanel放到一個jscrollpane中,並希望在其中顯示一個瀏覽器。當我將jfxpanel引用到index.html時,這是成功的。那時我無法應用d3來顯示Swing應用程序中的元素。 – 2015-02-12 04:34:02

+0

對不起,我可以知道什麼是「HTML意識」組件?這是否意味着d3不能在JFXPanel上工作? – 2015-02-12 04:44:38

回答

1

不知道在擺動嵌入HTML什麼,但我知道,在同一tag is not a good idea使用src和內嵌的JavaScript。

此外,TEST<script>標記內,所以它將作爲JavaScript執行並且無效。

最後,你假設d3正在加載,你的選擇器,追加和文本都很好。

也許嘗試:

<!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> 
+0

謝謝,但是我已經試過了,已經是b4了我發佈的qn.d3不能正常工作有人說這是一個許可問題。 – 2015-02-11 19:30:54