-
-
Save bibinmjose/eef59f1fb00a05fb05b01c4db29d93ca to your computer and use it in GitHub Desktop.
index_2.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
handedness | height | weight | avg | HR | Count | |
---|---|---|---|---|---|---|
B | 72.0 | 180.0 | 0.2405 | 13.0 | 104 | |
L | 73.0 | 185.0 | 0.248 | 23.5 | 316 | |
R | 73.0 | 185.0 | 0.233 | 14.0 | 737 |
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"> | |
<script src="http://d3js.org/d3.v4.min.js"></script> | |
<script src="http://dimplejs.org/dist/dimple.v2.3.0.min.js"></script> | |
<style> | |
circle.dimple-series-1{ | |
fill:red; | |
stroke:black; | |
} | |
h2{ | |
text-align: left; | |
font-family: Arial; | |
font-size: 18px; | |
} | |
h3{ | |
text-align: left; | |
font-family: Arial; | |
font-size: 14px; | |
} | |
</style> | |
<script type="text/javascript"> | |
function draw(data) { | |
/* | |
D3.js setup code | |
*/ | |
"use strict"; | |
var margin = 75, | |
width = 750 - 2*margin, | |
height = 500 - 2*margin; | |
// debugger; | |
// Header | |
d3.select("body") | |
.append("h2") | |
.text("Baseball Player statistics based on statistics") | |
d3.select("body") | |
.append("div") | |
.attr("class", "chart") | |
.attr("id", "chartContainer") | |
d3.select("body") | |
.append("h3") | |
.text("Performance") | |
// first chart and svg element | |
var svg = dimple.newSvg("body", width,height); | |
var myChart = new dimple.chart(svg, data); | |
myChart.setBounds(margin,margin-20,width-1.8*margin,height-1.5*margin) | |
// Adding Chart Axes | |
var x = myChart.addCategoryAxis("x", "handedness"); | |
x.addOrderRule(["R","L","B"]); | |
x.title = "Handedness" | |
var y1 = myChart.addMeasureAxis("y", "HR"); | |
y1.title = "Home Runs"; | |
y1.overrideMax = 26; | |
var y2 = myChart.addMeasureAxis("y", "avg"); | |
y2.title = "Average Runs"; | |
y2.overrideMax = 0.3; | |
y2.overrideMin = 0.21; | |
var z = myChart.addCategoryAxis("z", "Count"); | |
myChart.addSeries("Median Home Runs",dimple.plot.bubble,[x,y1,z]); | |
myChart.addSeries("Median Batting Average", dimple.plot.bubble,[x,y2,z]); | |
myChart.addLegend(4*margin,25,300,20, "right"); | |
myChart.draw(); | |
} | |
</script> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
/* | |
Use D3 (not dimple.js) to load the CSV file | |
and pass the contents of it to the draw function | |
*/ | |
d3.csv("baseball_median.csv", function(d) { | |
d['height'] = +d['height']; | |
d['weight'] = +d['weight']; | |
d['avg'] = +d['avg']; | |
d['HR'] = +d['HR']; | |
return d; | |
},draw); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment