D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
beskelton
Full window
Github gist
Knight Datavis Class Assignment 5 - data file has added column from wikipedia, 2 columns have been slightly transformed to be numbers
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>DataViz class Assignment 5</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; } circle:hover { fill: orange; } .axis path, .axis line { fill: none; stroke: black; shape-rendering: crispEdges; } .axis text { font-family: sans-serif; font-size: 11px; } </style> </head> <body> <h1>Module 5 Assignment</h1> <p>Data used is 2015 Men's NCAA Basketball Championship Odds of Winning Source: <a href="https://github.com/fivethirtyeight/data/blob/master/march-madness-predictions/bracket-00.csv">@FiveThirtyEight</a>, 2015 and <a href="https://en.wikipedia.org/wiki/2015_NCAA_Men%27s_Division_I_Basketball_Tournament#Tournament_seeds">Wikipedia entry</a> for 2015 Men's Basketball Championship to get overall rankings (new column)</p> <script type="text/javascript"> var w = 700; var h = 600; var padding = [ 20, 10, 50, 50 ]; //Top, right, bottom, left 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(5) .tickFormat(function(d) { return d + "%"; }); var yAxis = d3.svg.axis() .scale(yScale) .orient("left") .ticks(15); var svg = d3.select("body") .append("svg") .attr("width", w) .attr("height", h); d3.csv("marchmadnesswinningodds.csv", function(data) { xScale.domain([ d3.min(data, function(d) { return +d.rd7_win_num; }), d3.max(data, function(d) { return +d.rd7_win_num; }) ]); yScale.domain([ d3.min(data, function(d) { return +d.overall_seed; }), d3.max(data, function(d) { return +d.overall_seed; }) ]); var circles = svg.selectAll("circle") .data(data) .enter() .append("circle"); circles.attr("cx", function(d) { return xScale(d.rd7_win_num); }) .attr("cy", function(d) { return yScale(d.overall_seed); }) .attr("r", 4) .attr("fill", "#007dc1") .append("title") .text(function(d) { return d.team_name + "'s chance of winning is " + d.rd7_win_num + "%, and overall seed is " + d.overall_seed + "."; }); svg.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + (h - padding[2] + 10) + ")") .call(xAxis); // label for x axis svg.append("text") .attr("transform", "translate(" + (w / 2) + " ," + (h - 5) + ")") .style("text-anchor", "middle") .text("Percent Chance of Winning"); svg.append("g") .attr("class", "y axis") .attr("transform", "translate(" + (padding[3] - 10) + ",0)") .call(yAxis); svg.append("text") .attr("transform", "rotate(-90)") .attr("y", 0 - padding[4]) .attr("x",0 - (h / 2)) .attr("dy", "1em") .style("text-anchor", "middle") .text("Overall Seed"); }); </script> </body> </html>
Modified
http://d3js.org/d3.v3.js
to a secure url
https://d3js.org/d3.v3.js