-
Notifications
You must be signed in to change notification settings - Fork 0
/
SecondPage_ScatterPlot.html
92 lines (82 loc) · 2.7 KB
/
SecondPage_ScatterPlot.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<html>
<style>
{
font: 16px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.dot {
stroke: #000;
}
.tooltip {
position: absolute;
font-size: 12px;
width: auto;
height: auto;
pointer-events: none;
background: white;
border: 1px black;
color: black;
}
</style>
<body>
<div class="jumbotron" style="background-color: gray; color: white" aligncenter>
<h1 style="padding-left : 2%">Fuel Efficiency Analysis</h1></div>
<p style="padding-left : 2%">Generally speaking, the engine which performs better on city road will also performs better on highway. </p>
<script src='https://d3js.org/d3.v5.min.js'></script>
<style> circle {fill: orange; } </style>
<body onload='init()'>
<svg width=960 height=600>
</svg>
<script>
async function init() {
const data = await d3.csv("https://flunky.github.io/cars2017.csv")
.then(function(csvdata){
var output = new Array();
for(var i=0; i<csvdata.length; i++){
output.push({
C:+csvdata[i].EngineCylinders,
HMPG:+csvdata[i].AverageHighwayMPG,
CMPG:+csvdata[i].AverageCityMPG
});
}
return output;
})
var margin = 50;
var DOM_size = 500;
yScaler = d3.scaleLog().domain([10,150]).range([DOM_size,0]);
xScaler = d3.scaleLog().domain([10,150]).range([0,DOM_size]);
d3.select('svg')
.append("g")
.attr("transform","translate("+margin+","+margin+")")
.call(d3.axisLeft(yScaler)
.tickValues([10,20,50,100])
.tickFormat(d3.format("~s")));
d3.select('svg')
.append("g")
.attr("transform","translate("+margin+","+(DOM_size+margin)+")")
.call(d3.axisBottom(xScaler)
.tickValues([10,20,50,100])
.tickFormat(d3.format("~s")));
d3.select('svg')
.append("g")
.attr("transform","translate("+margin+","+margin+")")
.selectAll('circle')
.data(data)
.enter()
.append('circle')
.attr('cx',function(d){return xScaler(d.CMPG);})
.attr('cy',function(d){return yScaler(d.HMPG);})
.attr('r', 5)
}
</script>
<div aligncenter>
<br><h3>What is next?</h3></br>
<p style="padding-left : 2%">People would like to talk about which company makes the best engine. You may find the answer <a href="FinalPage_4C.html">here</a>. </p></br>
</div>
</body>
</html>