D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
hydrosquall
Full window
Github gist
CT IT Portfolio Budget
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Budget for Connecticut State IT Projects</title> <script type="text/javascript" src="https://d3js.org/d3.v3.js"></script> <style type="text/css"> body { background-color: white; font-family: Helvetica, Arial, sans-serif; } h1 { font-size: 24px; margin: 0; } p { font-size: 14px; margin: 10px 0 0 0; } svg { background-color: white; } rect:hover { fill: orange!important; } .axis path, .axis line { fill: none; stroke: black; shape-rendering: crispEdges; } .axis text { font-family: sans-serif; font-size: 11px; } .y.axis path, .y.axis line { opacity: 0; } </style> </head> <body> <h1>Budget for Connecticut State IT Projects</h1> <p>Information Technology projects reported to the Office of Policy and Management Source: <a href="https://data.ct.gov/Government/Information-Technology-Project-Portfolio/i7h5-rx65">Connecticut State Government</a>, 2015</p> <script type="text/javascript"> var w = 1200; var h = 180; var padding = [ 50, 10, 30, 90 ]; //Top, right, bottom, left var flatColors = { green : "#2ECC71", yellow : "#F5D76E", red : "#e74c3c" }; // logscale if needed var xScale = d3.scale.linear() .range([ padding[3], w - padding[1] - padding[3] ]); var yScale = d3.scale.linear() .range([ padding[0], h - padding[2] ]); var xAxis = d3.svg.axis() .scale(xScale) .orient("bottom") .ticks(8); var yAxis = d3.svg.axis() .scale(yScale) .orient("left") .tickFormat(function(d) { return 'Level: ' + d; }) .ticks(2); var body = d3.select("body"); var svg = body.append("svg") .attr("width", w) .attr("height", h); var colorCode = function(d) { switch(d.Level) { case "1": return flatColors.red; case "2": return flatColors.yellow; case "3": return flatColors.green; default: return "black"; } }; //Load in contents of CSV file d3.csv("ctitportfolio.csv", function(data) { data.sort( function(a,b) { return d3.ascending(+a.TotalBudget, +b.TotalBudget); }); xScale.domain([ d3.min(data, function(d) { return +d.TotalBudget; }), d3.max(data, function(d) { return +d.TotalBudget; }) ]); // Correllation data yScale.domain([ d3.min(data, function(d) { return +d.Level; }), d3.max(data, function(d) { return +d.Level; }) ]); // Assign labels - Numerical Labels // yScale.domain(d3.range(data.length)); // yScale.domain(data.map(function(d) {return d.ProjectName; } )); var circles = d3.select("svg").selectAll('circle') .data(data) .enter() .append('circle'); circles .attr("r", 0.3) .attr({ "cx": padding[3], "cy": function(d, i) { return yScale(d.Level); } }) .style({ "fill": colorCode, "opacity": 0.5 }) .append("title") .text(function(d) { return d.ProjectName + " : costs " + d.TotalBudget + ' Level: '+ d.Level; }); circles.sort(function(a,b) { return d3.ascending(+a.TotalBudget, +b.TotalBudget); }) .transition() .delay(function(d,i) { return i*10; }) .duration(2000) .attr("r", 7) .attr("cx", function(d) { return xScale(d.TotalBudget); } ) .attr("cy", function(d, i) { return yScale(d.Level); }); svg.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + (h - padding[2] + 10) + ")") .call(xAxis); svg.append("g") .attr("class", "y axis") .attr("transform", "translate(" + (padding[3] - 10) + ",0)") .call(yAxis); }); </script> </body> </html>
Modified
http://d3js.org/d3.v3.js
to a secure url
https://d3js.org/d3.v3.js