我正在用这个json做一个新的数组
http://data.cityofnewyork.us/resource/a7hj-s5px.json我存储邮政编码的地方,以及邮政编码在数据集中显示多少次。
它还有其他信息,如什么类型的噪音,因此,我将在稍后讨论。
下面是我要做的:通过这样做来检查数据集中有多少唯一的邮政编码
var zipValue = [];
var zipFrequency = [];
var map = d3.map();
data.forEach(function (d) {
var zipCount = map.get(d.incident_zip);
map.set(d.incident_zip, zipCount === undefined ? 1 : ++zipCount);
});
//storing the mapped values in an array
zipValue = map.keys(map);
zipFrequency = map.values(map);
var hScale = d3.scale.linear()
.domain([0, d3.max(newArray, function(d) { return d[1]; })])
.range([7, 70]);最后,尝试将hScale作为参数传递给形状。
这是我的小提琴http://jsfiddle.net/sghoush1/rYXbG/15/
我到底哪里出错了?
发布于 2013-08-25 21:22:23
你看过控制台了吗?我检查了你的小提琴,你犯了一个错误:
Uncaught TypeError: Object [object Array] has no method 'hScale'
而且,它似乎是由:
svg.selectAll("rect")
.data(newArray)
.enter()
.append("rect")
.attr("x", (k++) + 2)
.attr("y", 125)
.attr("width", 2)
.attr("height", function (d, i) {return d.hScale(d[1]);});最后一行应该是return hscale(d[1]);,而不是d.hscale。
https://stackoverflow.com/questions/18432502
复制相似问题