In fact, all you need is an ordinal scale! The axis takes care of the rest.
Check here .
I basically changed:
x.domain(dimensions = d3.keys(cars[0]).filter(function(d) { return d != "name" && (y[d] = d3.scale.linear() .domain(d3.extent(cars, function(p) { return +p[d]; })) .range([h, 0])); }));
in
x.domain(dimensions = d3.keys(cars[0]).filter(function(d) { if(d === "name") return false; if(d === "colour") { y[d] = d3.scale.ordinal() .domain(cars.map(function(p) { return p[d]; })) .rangePoints([h, 0]); } else { y[d] = d3.scale.linear() .domain(d3.extent(cars, function(p) { return +p[d]; })) .range([h, 0]); } return true; }));
And I added one column categorical column to the data. I was a bit lazy for hard coding, whose property is string.
Superboggly
source share