I built a grid of squares based on the example given in http://bl.ocks.org/bunkat/2605010. Now i am trying to color code each of the cells in the grid based on the data from csv file. Say for example, i have a csv file with data as
cell, col1
1,2
2,3
3,2
4,1
cells are colored based on data in col1. Like cell 1 colored with blue, cell 2 colored with green, cell 3 colored again with blue, cell 4 colored with red.
I have been trying something like this, but it doesn't work. Please help?
d3.text("frame.csv", function(datasetText) {
var parsedCSV = d3.csv.parseRows(datasetText);
var col = row.selectAll(".cell")
.data(function (d) { return d; })
.enter().append("svg:rect")
.attr("class", "cell")
.attr("x", function(d) { return d.x; })
.attr("y", function(d) { return d.y; })
.attr("width", function(d) { return d.width; })
.attr("height", function(d) { return d.height; })
.style("fill", function(d) { return color(parsedCSV[d].col1); })
.style("fill", '#FFF')
.style("stroke", '#555');
});