Created
April 12, 2016 16:15
-
-
Save b3nj4m/3c0dc0c6721c0c4bd283329b705fe863 to your computer and use it in GitHub Desktop.
dan.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Global Variables | |
var HEIGHT = 600; | |
var PADDING = 60; | |
DATA = {} | |
function type(d) { | |
surveys = [1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14] | |
for(var x = 0; x < surveys.length; x++) { | |
eval("d.Survey" + surveys[x] + " = +d.Survey" + surveys[x]) | |
} | |
return d; | |
} | |
function setupSVG() { | |
var divSvg = d3.select("#svgDiv") | |
temp = divSvg.style("width") | |
WIDTH = parseInt(temp.slice(0, temp.length-2)) - 30 | |
var svg = d3.select("#svgDiv") | |
.append("svg") | |
.attr("width", WIDTH) | |
.attr("height", HEIGHT) | |
.attr("border",1); | |
var borderPath = svg.append("rect") | |
.attr("x", 0) | |
.attr("y", 0) | |
.attr("height", HEIGHT) | |
.attr("width", WIDTH) | |
.style("stroke", "black") | |
.style("fill", "none") | |
.style("stroke-width", 1); | |
var xScale = d3.scale.linear() | |
.domain([0, 15]) | |
.range([PADDING, WIDTH - (PADDING/2)]); | |
var yScale = d3.scale.linear() | |
.domain([0, 40]) | |
.range([HEIGHT - PADDING, PADDING/2]); | |
var xAxis = d3.svg.axis() | |
.scale(xScale) | |
.orient("bottom") | |
.ticks(15); | |
var yAxis = d3.svg.axis() | |
.scale(yScale) | |
.orient("left") | |
.ticks(20); | |
/*svg.append("text") | |
.attr("transform", "rotate(-90)") | |
.attr("x", -1*yScale(50)) | |
.attr("y", 10) | |
.attr("dy", ".71em") | |
.attr("font-size", 20) | |
.style("text-anchor", "end") | |
.text("Score"); | |
svg.append("text") | |
.attr("x", xScale(50)) | |
.attr("y", HEIGHT - 20) | |
.attr("font-size", 20) | |
.style("text-anchor", "end") | |
.text("Skills Survey"); | |
*/ | |
svg.append("g") | |
.attr("class", "axis") | |
.attr("transform", "translate(0," + (HEIGHT - PADDING) + ")") | |
.call(xAxis); | |
svg.append("g") | |
.attr("class", "axis") | |
.attr("transform", "translate(" + PADDING + ",0)") | |
.call(yAxis); | |
} | |
function loadData() { | |
d3.csv("lise_csv.csv", type, function(error, data) { | |
DATA = data | |
var trs = d3.select("#studentList").selectAll('tr') | |
.data(data) | |
.enter() | |
.append("tr") | |
.append("td") | |
.html(function(d) { return d.FirstName + " " + d.LastName}) | |
}); | |
} | |
setupSVG(); | |
loadData(); | |
What is the deal with the eval
stuff at the top???
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use
selectAll
to select the elements that are going to match 1-1 with items in the dataset that you pass to.data()
. In the case of your table, that means usingd3.select('#studentList').selectAll('tr').data(data)
.