I've been stuck on this problem for hours at this point and I can't figure out the problem.
I've been following / with my own data set.
The error: Uncaught TypeError: Cannot read property 'type' of undefined - 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>
Here is a sample of the beginning of my json file:
I've been stuck on this problem for hours at this point and I can't figure out the problem.
I've been following http://bost.ocks/mike/map/ with my own data set.
The error: Uncaught TypeError: Cannot read property 'type' of undefined - 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>
Here is a sample of the beginning of my json file: http://pastebin./g0Lut36V
The problem seems to be in the file ../static/json/newjerseymun.json
.
The segment of the newjerseymin.json
you have posted does have the field objects
which contains a JSON object but there does not seem to be a subunits
field in that object, not at least in the segment you have posted. Hence, ns.objects.subunits
would be undefined
which causes the error.