I am building a dot plot histogram with d3.js v3 and I am trying to color code my data based off one of the variables I read in from my csv file (it's city, which there's 10 of them). Problem is every dot is the same color when I run it in the browser.
Anyone know whats going on?
Heres a snapshot of my code:
var data = d3.csv('happy.csv', function(data) {
data.forEach(function(d) {
d["index"] = d["index"];
d["name"] = d["name"];
d["city"] = d["city];
...
})
var colorScheme = d3.scale.ordinal()
.domain(data, (function(d) {
return d.city
}))
.range(["#FFADAF", "#FFC980", "#D9D9D9", "#9DACCB", "#95D1A5",
"#F586C6", "#BFDD81", "#F18489", "#80BCEC", "#FEFEA9"]);
...
var dots = groups.selectAll("circle")
.data(function(d) {
return d3.range(1, +d.index + 1)
})
.enter().append("circle")
.attr("class", "dot")
.attr("r", 7.5)
.attr("cy", function(d) {
return y(d)
})
.style("fill", function (d) { return colorScheme(d.city); } )
})