Visualization team completion times +/- from average completion time of 25m 00s
forked from mbostock's block: Bar Chart with Negative Values II
| license: gpl-3.0 |
Visualization team completion times +/- from average completion time of 25m 00s
forked from mbostock's block: Bar Chart with Negative Values II
| name | value | |
|---|---|---|
| Anh and Brian | 9.96 | |
| Chris and Giuseppe | 3.88 | |
| Balthazar and Chris | 2.9 | |
| Shan and Tim | -0.07 | |
| Austin and Jerome | -0.55 | |
| Eric and Jian | -3 | |
| Daniel and Wesam | -13.12 |
| <!DOCTYPE html> | |
| <meta charset="utf-8"> | |
| <style> | |
| .bar--positive { | |
| fill: #CEEBC6; | |
| } | |
| .bar--negative { | |
| fill: #D54B56; | |
| } | |
| .axis text { | |
| font: 10px sans-serif; | |
| } | |
| .axis path, | |
| .axis line { | |
| fill: none; | |
| stroke: gray; | |
| shape-rendering: crispEdges; | |
| } | |
| </style> | |
| <body> | |
| <script src="//d3js.org/d3.v3.min.js"></script> | |
| <script> | |
| var margin = {top: 20, right: 30, bottom: 40, left: 30}, | |
| width = 960 - margin.left - margin.right, | |
| height = 500 - margin.top - margin.bottom; | |
| var x = d3.scale.linear() | |
| .range([0, width]); | |
| var y = d3.scale.ordinal() | |
| .rangeRoundBands([0, height], 0.1); | |
| var xAxis = d3.svg.axis() | |
| .scale(x) | |
| .orient("bottom"); | |
| var yAxis = d3.svg.axis() | |
| .scale(y) | |
| .orient("left") | |
| .tickSize(6, 0); | |
| var svg = d3.select("body").append("svg") | |
| .attr("width", width + margin.left + margin.right) | |
| .attr("height", height + margin.top + margin.bottom) | |
| .append("g") | |
| .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
| d3.csv("data.csv", type, function(error, data) { | |
| x.domain(d3.extent(data, function(d) { return d.value; })).nice(); | |
| y.domain(data.map(function(d) { return d.name; })); | |
| svg.selectAll(".bar") | |
| .data(data) | |
| .enter().append("rect") | |
| .attr("class", function(d) { return "bar bar--" + (d.value < 0 ? "negative" : "positive"); }) | |
| .attr("x", function(d) { return x(Math.min(0, d.value)); }) | |
| .attr("y", function(d) { return y(d.name); }) | |
| .attr("rx", 5) | |
| .attr("ry", 5) | |
| .attr("width", function(d) { return Math.abs(x(d.value) - x(0)); }) | |
| .attr("height", y.rangeBand()); | |
| svg.append("g") | |
| .attr("class", "x axis") | |
| .attr("transform", "translate(0," + height + ")") | |
| .call(xAxis); | |
| var tickNegative = svg.append("g") | |
| .attr("class", "y axis") | |
| .attr("transform", "translate(" + x(0) + ",0)") | |
| .call(yAxis) | |
| .selectAll(".tick") | |
| .filter(function(d, i) { return data[i].value < 0; }); | |
| tickNegative.select("line") | |
| .attr("x2", 6); | |
| tickNegative.select("text") | |
| .attr("x", 9) | |
| .style("text-anchor", "start"); | |
| }); | |
| function type(d) { | |
| d.value = +d.value; | |
| return d; | |
| } | |
| </script> |
| �PNG | |