D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
BenHeubl
Full window
Github gist
Benefits
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Cleaning Up</title> <script type="text/javascript" src="https://d3js.org/d3.v3.min.js"></script> <style type="text/css"> body { background-color: white; font-family: Helvetica, Arial, sans-serif; } h1 { font-family:Georgia,serif; color: #e41c53; font-size: 50px; font-variant: small-caps; text-transform: none; font-weight: 100; margin-bottom: 0; } p { font-family: "Helvetica Neue", "Lucida Grande", Helvetica, Arial, Verdana, sans-serif; font-size: 14px; margin-top: .5em; color: #1d9ebf; } li { font-family: "Helvetica Neue", "Lucida Grande", Helvetica, Arial, Verdana, sans-serif; font-size: 14px; margin-top: .5em; color: #1d9ebf; } a { font-family: "Helvetica Neue", "Lucida Grande", Helvetica, Arial, Verdana, sans-serif; font-size: 9px; margin-top: .5em; color: grey; } svg { background-color: white; } rect:hover { fill: #FFD5E6; } .axis path, .axis line { fill: none; stroke: none; shape-rendering: crispEdges; } .axis text { font-family: sans-serif; font-size: 7px; color: white; } .y.axis path, .y.axis line { opacity: 0; } </style> </head> <body> <h1>Which solutions are leading in terms of “Benefits”</h1> <p>Data source: <a href="https://vandrico.com/">Vandrico Inc.</a>, 2015</p> <script type="text/javascript"> var w = 500; var h = 1000; var padding = [ 0, 10, 30, 20 ]; //Top, right, bottom, left var widthScale = d3.scale.linear() .range([ 0, w - padding[1] - padding[3] ]); var heightScale = d3.scale.ordinal() .rangeRoundBands([ padding[0], h - padding[2] ], 0.09); var xAxis = d3.svg.axis() .scale(widthScale) .orient("bottom"); var yAxis = d3.svg.axis() .scale(heightScale) .orient("right"); var svg = d3.select("body") .append("svg") .attr("width", w) .attr("height", h); d3.csv("data.csv", function(data) { data.sort(function(a, b) { return d3.descending(+a.Benefits, +b.Benefits); }); widthScale.domain([ 0, d3.max(data, function(d) { return +d.Benefits; }) ]); heightScale.domain(data.map(function(d) { return d.DeviceName; } )); var rects = svg.selectAll("rect") .data(data) .enter() .append("rect"); rects.attr("x", padding[3]) .attr("y", function(d) { return heightScale(d.DeviceName); }) .attr("width", function(d) { return widthScale(d.Benefits); }) .attr("height", heightScale.rangeBand()) .attr("fill", "#D5F4FC") .append("title") .text(function(d) { return d.DeviceName + " :" + d.DeviceDescription; }); svg.append("g") .attr("class", "x axis") .attr("transform", "translate(" + padding[3] + "," + (h - padding[2]) + ")") .call(xAxis); svg.append("g") .attr("class", "y axis") .attr("transform", "translate(" + padding[1] + ",0)") .call(yAxis); }); </script> </body> </html>
Modified
http://d3js.org/d3.v3.min.js
to a secure url
https://d3js.org/d3.v3.min.js