Javascript d3 topojson未捕获类型错误:无法读取属性';0';空的 漫画 var cartogram=d3.cartogram() .投影(d3.geo.albersUsa()) .价值(功能(d){ 返回Math.random()*100; }); d3.json(“http://zhicongchen.github.io/newsmap/data/china_cities_topo.json,函数(拓扑){ var features=cartogram(拓扑、拓扑、对象、中国城市、几何); d3.选择(“svg”).选择全部(“路径”) .数据(特征) .输入() .append(“路径”) .attr(“d”,cartogram.path); });

Javascript d3 topojson未捕获类型错误:无法读取属性';0';空的 漫画 var cartogram=d3.cartogram() .投影(d3.geo.albersUsa()) .价值(功能(d){ 返回Math.random()*100; }); d3.json(“http://zhicongchen.github.io/newsmap/data/china_cities_topo.json,函数(拓扑){ var features=cartogram(拓扑、拓扑、对象、中国城市、几何); d3.选择(“svg”).选择全部(“路径”) .数据(特征) .输入() .append(“路径”) .attr(“d”,cartogram.path); });,javascript,jquery,d3.js,topojson,cartogram,Javascript,Jquery,D3.js,Topojson,Cartogram,我们尝试了上面的玩具代码来可视化中国城市的卡通图。但是,我们得到一个未捕获的TypeError:无法读取null的属性“0”。有什么想法吗?检查JavaScript控制台是否有错误XMLHttpRequest无法加载https://github.com/zhicongchen/newsmap/blob/gh-pages/data/china_cities_topo.json. 请求的资源上不存在“Access Control Allow Origin”标头。起源'http://run.plnkr

我们尝试了上面的玩具代码来可视化中国城市的卡通图。但是,我们得到一个未捕获的TypeError:无法读取null的属性“0”。有什么想法吗?

检查JavaScript控制台是否有错误<代码>XMLHttpRequest无法加载https://github.com/zhicongchen/newsmap/blob/gh-pages/data/china_cities_topo.json. 请求的资源上不存在“Access Control Allow Origin”标头。起源'http://run.plnkr.co因此,不允许访问。这是CORS问题。很抱歉我的错误。我已经编辑了我的代码。问题依然存在。你几乎肯定不想看到中国的albersUsa投影。@Larskothoff:非常有用。检查你的JavaScript控制台是否有错误<代码>XMLHttpRequest无法加载https://github.com/zhicongchen/newsmap/blob/gh-pages/data/china_cities_topo.json. 请求的资源上不存在“Access Control Allow Origin”标头。起源'http://run.plnkr.co因此,不允许访问。这是CORS问题。很抱歉我的错误。我已经编辑了我的代码。问题依然存在。你几乎肯定不想要中国的阿尔伯苏萨预测。@Larskothoff:非常有用。
<!DOCTYPE HTML>
<html lang="en">
  <head>
    <title>cartogram</title>
    <link rel="stylesheet" type="text/css" href="footprint.css"/>
    <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
    <script src="http://d3js.org/queue.v1.min.js"></script>
    <script src="http://d3js.org/topojson.v1.min.js"></script>
    <script type="text/javascript" src="http://prag.ma/code/d3-cartogram/cartogram.js"></script>
    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  </head>
  <body>
    <script type="text/javascript">
    var cartogram = d3.cartogram()
  .projection(d3.geo.albersUsa())
  .value(function(d) {
    return Math.random() * 100;
  });
 d3.json("http://zhicongchen.github.io/newsmap/data/china_cities_topo.json", function(topology) {
  var features = cartogram(topology, topology.objects.china_cities.geometries);
  d3.select("svg").selectAll("path")
    .data(features)
    .enter()
    .append("path")
      .attr("d", cartogram.path);
 });
 </script>
  </body>
</html>