How can I display my histogram in d3 to show a summary of how many $$ points each city receives using this data type?
{
School: "PS 1",
Borough: Q,
Award: 1000
},
{
School: "PS 2",
Borough: Q,
Award: 3000
},
School: "PS 4",
Borough: X,
Award: 3000
}
At the moment, my histogram is organized by the name X: the name of the school and Y: Award $. But I want to show a $ reward based on each district.
Excerpt:
var manhattanList = [];
var queensList = [];
var brooklynList = [];
var statenIsList = [];
var bronxList = [];
for (i=0; i<data.length; i++) {
if (data[i].boro === "M") {
manhattanList.push(data[i])
} else if (data[i].boro == "Q") {
queensList.push(data[i])
} else if (data[i].boro == "X") {
bronxList.push(data[i])
} else if (data[i].boro == "R") {
statenIsList.push(data[i])
} else {
brooklynList.push(data[i])
}
};
var width = 1000;
var height = 10000;
var widthScaled = d3.scale.linear()
.domain([0, 83300000])
.range([0, width]);
var colorScale = d3.scale.linear()
.domain([0, 83300000])
.range(["red", "blue"]);
var axis = d3.svg.axis()
.ticks(10)
.scale(widthScaled);
var canvas = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height)
.attr("transform", "translate(100, 100)")
.call(axis);
canvas.selectAll("rect")
.data(data)
.enter()
.append("rect")
.attr("width", function(d) { return widthScaled(+d.award); })
.attr("height", 48)
.attr("y", function(d, i) { return i * 50; })
.attr("fill", function(d) {
return "hsl(" + Math.random() * 360 + ",60%,80%)"
});
canvas.selectAll("text")
.data(data)
.enter()
.append("text")
.attr("fill", "white")
.attr("y", function(d, i) { return i * 50 + 24; })
.text(function (d) { return d.name; })
});
Here is my JSBIN: https://jsbin.com/hiruci/edit?html,output
source
share