未捕获的类型错误: 无法使用 d3 读取未定义的属性'type'.js



这一点上,我已经在这个问题上停留了几个小时,我无法弄清楚问题所在。

我一直在用自己的数据集关注 http://bost.ocks.org/mike/map/。

错误:未

捕获的类型错误:无法读取未定义的属性"类型" - topojson.v0.min.js:1

<!DOCTYPE html>
<head>
<meta charset="utf-8">
<style>
path {
  fill: #ccc;
  stroke: #fff;
  stroke-width: .5px;
}
path:hover {
  fill: red;
}
</style>
</head>
<body>
<script src="../static/js/d3.min.js"></script>
<script src="../static/js/topojson.v0.min.js"></script>
<script>

var width = 900,
    height = 900;
var path = d3.geo.path();
var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);

d3.json("../static/json/newjerseymun.json", function(nj) {
  svg.append("path")
      .datum(topojson.object(nj, nj.objects.subunits))
      .attr("d", d3.geo.path().projection(d3.geo.mercator()));
});
</script>
</body>

这是我的 json 文件开头的示例:http://pastebin.com/g0Lut36V

问题似乎出在文件../static/json/newjerseymun.json 中。

您发布的newjerseymin.json段确实具有包含 JSON 对象的字段objects,但该对象中似乎没有subunits字段,至少在您发布的细分中没有。因此,ns.objects.subunits undefined导致错误。

最新更新