I am trying to create a D3.js packed circle diagram .
When I paste data into an HTML file, it works fine. When I put the data in an external file, I get nothing (empty DOM, without console messages).
If you uncomment the var data declaration and comment out d3.json (and the corresponding closing parentheses), it works fine.
I see the file “2013 Inf-2.json” in the browser and it looks well formed (it passes the jsonlint check). It includes everything from the first "{" to / including the last "}". As an embedded example.
I run this via httpd (: 80) on OSX Mavericks and try to display the chart in Chrome or Safari.
<!DOCTYPE html>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="./d3.v3.min.js"></script>
</head>
<body>
<div id="chart2"></div>
<script type="text/javascript">
var w = 640, h = 480;
var data = d3.json("2013 Inf-2.json", function(error, root) {
var canvas = d3.select("#chart2")
.append("svg:svg")
.attr("width", w)
.attr("height", h);
var nodes = d3.layout.pack()
.value(function(d) { return d.size; })
.size([w, h])
.nodes(data);
nodes.shift();
canvas.selectAll("circles")
.data(nodes)
.enter().append("svg:circle")
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; })
.attr("r", function(d) { return d.r; })
.attr("fill", "green")
.attr("stroke", "grey");
});
</script>
</html>