d3js - 简单渲染不起作用

时间:2015-04-09 05:09:15

标签: javascript d3.js

我正在尝试使用d3js创建一个简单的列表信息,而不是工作。任何人弄清楚我在这里做错了什么?



var obj = {
"status": ["GOOD SERVICE"],
"name": ["123"],
"url": [null],
"text": ["..."],
"plannedworkheadline": [null],
"Time": [" 7:35AM"],
"Date": ["12/15/2011"]
}

function draw(data) {
			"use strict";
			d3.select("body")
			.append("ul")
			.selectAll("li")
			.data(data)
			.enter()
			.append("li")
			.text(function (d) {
				return d.name + ": " + d.status;
			});
		};

d3.json(obj, draw);

<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

data必须是数组。

&#13;
&#13;
var obj = [{
"status": ["GOOD SERVICE"],
"name": ["123"],
"url": [null],
"text": ["..."],
"plannedworkheadline": [null],
"Time": [" 7:35AM"],
"Date": ["12/15/2011"]
}]

function draw(data) {
			"use strict";
			d3.select("body")
			.append("ul")
			.selectAll("li")
			.data(data)
			.enter()
			.append("li")
			.text(function (d) {
				return d.name + ": " + d.status;
			});
		};

draw(obj);
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
&#13;
&#13;
&#13;