var margin9 = {top: 20, right: 20, bottom: 30, left: 40}, width9 = 960 - margin.left - margin.right, height9 = 500 - margin.top - margin.bottom; var x9 = d3.scale.ordinal() .rangeRoundBands([0, width9], .1); var y9 = d3.scale.linear() .range([height9, 0], 0.1); var xAxis9 = d3.svg.axis() .scale(x9) .orient("bottom"); var yAxis9 = d3.svg.axis() .scale(y9) .orient("left") .tickSize(0) .tickPadding(10); var cValue9 = function(d) { if ( d.Class == "Americas") { return "#35586C";} else { if ( d.Class == "Europe") { return "#8E2323";} else { if ( d.Class == "EasternEurope") { return "#5C5C5C";} else { if ( d.Class == "Asia") { return "#FF8600";} else { if ( d.Class == "SouthAsia") { return "#397D02";} else { if ( d.Class == "Oceania") { return "#388E8E";} else { return "#5E2D79";} } } } } } }; var tooltip = d3.select("body").append("div") .attr("class", "tooltip") .style("opacity", 0); var svg9 = d3.select("body").append("svg") .attr("width", width9 + margin9.left + margin9.right) .attr("height", height9 + margin9.top + margin9.bottom) .append("g") .attr("transform", "translate(" + margin9.left + "," + margin9.top + ")"); d3.csv("Correlations2.csv", type, function(error, data) { x9.domain(data.map(function(d) { if (d.Type != "Country") {return d.Class;} })); //y9.domain(d3.extent(data, function(d) { return d.Corr; })).nice(); y9.domain([-.8,.8]); svg9.selectAll(".bar") .data(data) .enter().append("rect") .filter(function(d) {return (d.Type != "Country")}) // .attr("class", function(d) { return "bar bar--" + (d.Corr < 0 ? "negative" : "positive"); }) .style("fill", cValue9) .attr("x", function(d) { return x9(d.Class); }) .attr("y", function(d) { return y9(Math.max(0, d.Corr)); }) .attr("width", x9.rangeBand()) .attr("height", function(d) { return Math.abs(y9(d.Corr) - y9(0)); }) .on("mouseover", function(d) { tooltip.transition() .duration(200) .style("opacity", .9); tooltip.html(d["Class"] + "
(" + d.Corr + ")") .style("left", (d3.event.pageX -5) + "px") .style("top", (d3.event.pageY + 50) + "px"); }) .on("mouseout", function(d) { tooltip.transition() .duration(500) .style("opacity", 0); }); svg9.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + height9 + ")") .call(xAxis9) .append("text") .attr("class", "label") .attr("x", width9) .attr("y", -15) .style("text-anchor", "end") .text("Region"); //.text("Region"); svg9.append("g") .attr("class", "y axis") .attr("transform", "translate(" + 0 + ",0)") .call(yAxis9) .append("text") .attr("class", "label") .attr("transform", "rotate(-90)") .attr("y", 6) .attr("dy", ".71em") .style("text-anchor", "end") .text("Corr FX Rate and GDP Change");; //Add Title svg9.append("text") .attr("x", (width9 / 2)) .attr("y", 0 - (margin9.top / 6)) .attr("text-anchor", "middle") .style("font-size", "16px") .style("text-decoration", "underline") .text("Regional Correlation"); }); function type(d) { d.value = +d.Corr; return d; }