Created
May 5, 2018 21:15
-
-
Save lingyielia/8bf3ea745e6afaceec6b1f5840c8b26b to your computer and use it in GitHub Desktop.
data vis // source https://jsbin.com/pasijih
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>data vis</title> | |
<style id="jsbin-css"> | |
.y-axis path { | |
display: none; | |
} | |
.label { | |
fill: black; | |
font-size: 14px; | |
} | |
</style> | |
</head> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.3/d3.min.js"></script> | |
<body> | |
<div id="chart"> | |
<svg width="400" height="300" id="svg1"></svg> | |
</div> | |
<script id="jsbin-javascript"> | |
var casebytype = "https://raw.githubusercontent.com/YukunVVan/DataViz-Project/master/DataPreprocess/defalt/casebytype.json?token=AefhM-YOnFm6lx7spN5cVf11NBIm2OYLks5a90_PwA%3D%3D"; | |
d3.queue() | |
.defer(d3.json, casebytype) | |
.await(createBar); | |
function createBar(error, typedata) { | |
var svg1 = d3.select("#svg1"), | |
g = svg1.append("g"), | |
type = typedata.map(function(d) {return d.type;}), | |
count = typedata.map(function(d) {return d.count;}), | |
maxValue = d3.max(count); | |
var w = d3.scaleLinear() | |
.domain([0, maxValue]) | |
.rangeRound([0, 300]); | |
g.selectAll(".mark") | |
.data(count) | |
.enter() | |
.append('rect') | |
.attr('class', 'mark') | |
.attr('x', 120) | |
.attr('y', function(d,i) {return 50+i*24;}) | |
.attr('width', function(d,i) {return w(d);}) | |
.attr('height', 22) | |
.attr('fill','lightgrey'); | |
var xAxis = d3.axisBottom() | |
.scale(w) | |
.ticks(5); | |
g.append("g") | |
.attr("class", "x-axis") | |
.attr("transform", "translate(120,170)") | |
.call(xAxis) | |
.append("text") | |
.attr("class", "label") | |
.style("text-anchor", "middle") | |
.attr("transform","translate(100,40)") | |
.text("Complaints by Type"); | |
var y = d3.scalePoint().domain(type).range([0,100]); | |
var yAxis = d3.axisLeft() | |
.scale(y); | |
g.append("g") | |
.attr("class", "y-axis") | |
.attr("transform", "translate(116,60)") | |
.call(yAxis); | |
} | |
</script> | |
<script id="jsbin-source-css" type="text/css">.y-axis path { | |
display: none; | |
} | |
.label { | |
fill: black; | |
font-size: 14px; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var casebytype = "https://raw.githubusercontent.com/YukunVVan/DataViz-Project/master/DataPreprocess/defalt/casebytype.json?token=AefhM-YOnFm6lx7spN5cVf11NBIm2OYLks5a90_PwA%3D%3D"; | |
d3.queue() | |
.defer(d3.json, casebytype) | |
.await(createBar); | |
function createBar(error, typedata) { | |
var svg1 = d3.select("#svg1"), | |
g = svg1.append("g"), | |
type = typedata.map(function(d) {return d.type;}), | |
count = typedata.map(function(d) {return d.count;}), | |
maxValue = d3.max(count); | |
var w = d3.scaleLinear() | |
.domain([0, maxValue]) | |
.rangeRound([0, 300]); | |
g.selectAll(".mark") | |
.data(count) | |
.enter() | |
.append('rect') | |
.attr('class', 'mark') | |
.attr('x', 120) | |
.attr('y', function(d,i) {return 50+i*24;}) | |
.attr('width', function(d,i) {return w(d);}) | |
.attr('height', 22) | |
.attr('fill','lightgrey'); | |
var xAxis = d3.axisBottom() | |
.scale(w) | |
.ticks(5); | |
g.append("g") | |
.attr("class", "x-axis") | |
.attr("transform", "translate(120,170)") | |
.call(xAxis) | |
.append("text") | |
.attr("class", "label") | |
.style("text-anchor", "middle") | |
.attr("transform","translate(100,40)") | |
.text("Complaints by Type"); | |
var y = d3.scalePoint().domain(type).range([0,100]); | |
var yAxis = d3.axisLeft() | |
.scale(y); | |
g.append("g") | |
.attr("class", "y-axis") | |
.attr("transform", "translate(116,60)") | |
.call(yAxis); | |
} | |
</script></body> | |
</html> |
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
.y-axis path { | |
display: none; | |
} | |
.label { | |
fill: black; | |
font-size: 14px; | |
} |
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
var casebytype = "https://raw.githubusercontent.com/YukunVVan/DataViz-Project/master/DataPreprocess/defalt/casebytype.json?token=AefhM-YOnFm6lx7spN5cVf11NBIm2OYLks5a90_PwA%3D%3D"; | |
d3.queue() | |
.defer(d3.json, casebytype) | |
.await(createBar); | |
function createBar(error, typedata) { | |
var svg1 = d3.select("#svg1"), | |
g = svg1.append("g"), | |
type = typedata.map(function(d) {return d.type;}), | |
count = typedata.map(function(d) {return d.count;}), | |
maxValue = d3.max(count); | |
var w = d3.scaleLinear() | |
.domain([0, maxValue]) | |
.rangeRound([0, 300]); | |
g.selectAll(".mark") | |
.data(count) | |
.enter() | |
.append('rect') | |
.attr('class', 'mark') | |
.attr('x', 120) | |
.attr('y', function(d,i) {return 50+i*24;}) | |
.attr('width', function(d,i) {return w(d);}) | |
.attr('height', 22) | |
.attr('fill','lightgrey'); | |
var xAxis = d3.axisBottom() | |
.scale(w) | |
.ticks(5); | |
g.append("g") | |
.attr("class", "x-axis") | |
.attr("transform", "translate(120,170)") | |
.call(xAxis) | |
.append("text") | |
.attr("class", "label") | |
.style("text-anchor", "middle") | |
.attr("transform","translate(100,40)") | |
.text("Complaints by Type"); | |
var y = d3.scalePoint().domain(type).range([0,100]); | |
var yAxis = d3.axisLeft() | |
.scale(y); | |
g.append("g") | |
.attr("class", "y-axis") | |
.attr("transform", "translate(116,60)") | |
.call(yAxis); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment