2016-02-17 101 views
0

的小例子,我不能夠運行從這裏最小indentedTree例子:我使用的是D3(3.5.15)和nvd3的最新版本 http://nvd3.org/examples/indentedtree.html未運行indentedTree

(1.8.1) 。

我的文件夾如下所示。

enter image description here

我不明白,爲什麼下面的代碼不會顯示在瀏覽器中任何東西,因爲它基本上是提到以上鍊接的小例子的複製粘貼。有任何想法嗎?

mychart.html

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Table</title> 
     <link href="nv.d3.min.css" rel="stylesheet" type="text/css"> 
     <script src="d3.min.js"></script> 
     <script src="nv.d3.min.js"></script> 
    </head> 
    <body> 
    <div id="chart"></div> 
     <script src="mychart.js"></script> 
    </body> 
</html> 

mychart.js

function testData() { 
    return [{ 
    key: 'NVD3', 
    url: 'http://novus.github.com/nvd3', 
    values: [ 
     { 
     key: "Charts", 
     _values: [ 
      { 
      key: "Simple Line", 
      type: "Historical", 
      url: "http://novus.github.com/nvd3/ghpages/line.html" 
      }, 
      { 
      key: "Scatter/Bubble", 
      type: "Snapshot", 
      url: "http://novus.github.com/nvd3/ghpages/scatter.html" 
      }, 
      { 
      key: "Stacked/Stream/Expanded Area", 
      type: "Historical", 
      url: "http://novus.github.com/nvd3/ghpages/stackedArea.html" 
      }, 
      { 
      key: "Discrete Bar", 
      type: "Snapshot", 
      url: "http://novus.github.com/nvd3/ghpages/discreteBar.html" 
      }, 
      { 
      key: "Grouped/Stacked Multi-Bar", 
      type: "Snapshot/Historical", 
      url: "http://novus.github.com/nvd3/ghpages/multiBar.html" 
      }, 
      { 
      key: "Horizontal Grouped Bar", 
      type: "Snapshot", 
      url: "http://novus.github.com/nvd3/ghpages/multiBarHorizontal.html" 
      }, 
      { 
      key: "Line and Bar Combo", 
      type: "Historical", 
      url: "http://novus.github.com/nvd3/ghpages/linePlusBar.html" 
      }, 
      { 
      key: "Cumulative Line", 
      type: "Historical", 
      url: "http://novus.github.com/nvd3/ghpages/cumulativeLine.html" 
      }, 
      { 
      key: "Line with View Finder", 
      type: "Historical", 
      url: "http://novus.github.com/nvd3/ghpages/lineWithFocus.html" 
      } 
     ] 
     }, 
     { 
     key: "Chart Components", 
     _values: [ 
      { 
      key: "Legend", 
      type: "Universal", 
      url: "http://novus.github.com/nvd3/examples/legend.html" 
      } 
     ] 
     } 
    ] 
    }]; 
} 


nv.addGraph(function() { 
    var chart = nv.models.indentedTree() 
    .columns([ 
     { 
     key: 'key', 
     label: 'Name', 
     width: '75%', 
     type: 'text', 
     classes: function(d) { return d.url ? 'clickable name' : 'name' }, 
     click: function(d) { 
      if (d.url) window.location.href = d.url; 
     } 
     }, 
     { 
     key: 'type', 
     label: 'Type', 
     width: '25%', 
     type: 'text' 
     } 
    ]) 
    ; 

    d3.select('#chart') 
    .datum(testData()) 
    .call(chart) 
    ; 

    return chart; 
}); 

回答

1

是啊,對CDN的NVD3(1.8.1)的最新不必支持nv.models.indentedTree

於是拿起來自這裏的nv.d3 http://nvd3.org/assets/js/nv.d3.js和css來自http://nvd3.org/assets/css/nv.d3.css

工作代碼here