Of course, you can use the indices of the 2d array to draw a heat map. I put together a quick example at http://jsfiddle.net/uArga/4/ .
Assuming your data looks like this:
var data = [[3,5],[9,2]];
First, I set up some basic scales for calculating the x and y offsets depending on the size of the data and the size of the chart. This makes it easy to resize the chart by changing the height and width parameters without having to manually recalculate how large each cell is.
var x = d3.scale.linear() .range([0, width]) .domain([0,data[0].length]); var y = d3.scale.linear() .range([0, height]) .domain([0,data.length]);
You can then add each row to the heat map.
var row = svg.selectAll(".row") .data(data) .enter().append("svg:g") .attr("class", "row");
Then add each cell to the row using a subquery. There may be a cleaner way to do this, but I basically just fix the row number next to the data for each cell. Then I use scales to determine x , y , height and width for each cell.
var col = row.selectAll(".cell") .data(function (d,i) {return d.map(function(a){return {value: a, row: i};})}) .enter().append("svg:rect") .attr("class", "cell") .attr("x", function(d, i) { return x(i); }) .attr("y", function(d, i) { return y(d.row); }) .attr("width", x(1)) .attr("height", y(1)) .style("fill", function(d) { return colorScale(d.value); });