<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3 Demo: SVG with data</title>
<script type="text/javascript" src="d3/d3.v3.js"></script>
<style type="text/css">
</style>
</head>
<body>
<script type="text/javascript">
var dataset = {
"entry":[
{"date": "2011-03-18T00:00:04"},
{"date": "2011-04-18T00:05:03"},
{"date": "2011-03-29T00:10:04"},
{"date": "2011-05-19T00:15:03"},
{"date":"2011-06-12T00:20:03"},
{"date": "2011-08-09T00:25:03"}
],
"entry" :[
{"date": "2012-03-18T00:00:04"},
{"date": "2012-04-18T00:05:03"},
{"date": "2012-03-29T00:10:04"},
{"date": "2012-05-19T00:15:03"},
{"date":"2012-06-12T00:20:03"},
{"date": "2012-08-09T00:25:03"}
]
}
console.log(dataset.entry);
var height = 600;
var width = 500;
var x = d3.time.scale().domain([new Date(2011, 0, 1,23,33,00), new Date(2013, 0, 1, 23, 59)]).range([0, width]);
var svg = d3.selectAll("body")
.append("svg")
.attr("width",width)
.attr("height",height)
.attr("shape-rendering","crispEdges");
svg.selectAll("body")
.data(dataset)
.enter()
.append("rect")
.attr("width", 4)
.attr("height",12)
.attr("x", function(d) { return x(new Date(d.entry.date)); } )
.attr("y",function(d,i){return i*10;})
.attr("fill","steelblue");
</script>
</body>
</html>
这是我创建的一个简单文件。目的是模仿甘特图。如您所见,数组中共有 12 个值。我做错了什么,导致无法打印。
谁能指导我?