var proj = d3.geo.mercator(); var path = d3.geo.path().projection(proj); var map = d3.select("#map") .append("svg:svg") .attr("width", 400) .attr("height", 500) .call(initialize); var ireland = map.append("svg:g") .attr("id", "ireland") .attr("class", "Blues"); //load the geoJSON file for drawing the map d3.json("ireland.json", function (json) { ireland.selectAll("path") .data(json.features) .enter().append("path") .attr("d", path); }); // load the data d3.json("counties.json", function(json) { //this works data = json; ireland.selectAll("path") .attr("class", quantize) .attr("d", path) .on("mouseover", function(d) { var title = d3.select("#subtitle") .text(d.id); var subblurb = d3.select("#subblurb") .text(d.comment); // console.log(d.amount) }) }); function quantize(d) { // return "q" + Math.min(8, ~~(data[d.id] * 9 / 12)) + "-9"; //this works for an incorrectly formed JSON file return "q" + Math.min(8, ~~(function(d) {return d[0];} * 9 / 12)) + "-9"; //this doesnt work } //setup scale & position of map function initialize() { proj.scale(27000); proj.translate([799, 5010]); }