【发布时间】:2015-01-23 21:29:36
【问题描述】:
我一直在使用 mbostocks github 帐户中的 D3 和 TopoJSON 示例我一直在做的 D3 和 topoJSON 工作也没有出现在浏览器或本地 nodejs http-server 中。我刚刚从 mbostocks github 复制和粘贴的示例也没有出现。这个例子如下。现在我很困惑为什么它没有出现在浏览器中。我在文件中有脚本 src 以及所需的 html 样板。如果有人可以请告诉我为什么它没有运行那会很棒。我刚开始使用 D3 和 topoJSON。谢谢!
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<style>
.states {
fill: none;
stroke: #fff;
stroke-linejoin: round;
}
</style>
</head>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 500;
var fill = d3.scale.log()
.domain([10, 500])
.range(["brown", "steelblue"]);
var path = d3.geo.path();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("/mbostock/raw/4090846/us.json", function(error, us) {
svg.append("g")
.attr("class", "counties")
.selectAll("path")
.data(topojson.feature(us, us.objects.counties).features)
.enter().append("path")
.attr("d", path)
.style("fill", function(d) { return fill(path.area(d)); });
svg.append("path")
.datum(topojson.mesh(us, us.objects.states, function(a, b) { return a.id !== b.id; }))
.attr("class", "states")
.attr("d", path);
});
</script>
</body>
</html>
【问题讨论】:
标签: javascript html d3.js geojson topojson