-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscatter.js
76 lines (67 loc) · 2.09 KB
/
scatter.js
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
//creating the scatter plot data for numbers of players vs metascore
// set the dimensions and margins of the graph
var margin = {top:20, right: 60, bottom: 80, left: 80},
width = 900 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;
// append the svg object to the body of the page
var svg = d3.select("#my_dataviz")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")")
//Read the data
d3.csv('Assets/Data/new_steam_db1.csv', function(data) {
console.log(data)
// Add X axis
var x = d3.scaleLinear()
.domain([0, 0])
.range([ 0, width ]);
svg.append("g")
.attr("class", "myXaxis")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x))
.attr("opacity", "0")
// Add Y axis
var y = d3.scaleLinear()
.domain([0, 1])
.range([ height, 0]);
svg.append("g")
.call(d3.axisLeft(y));
// Add dots
svg.append('g')
.selectAll("dot")
.data(data)
.enter()
.append("circle")
.attr("cx", function (d) { return x(d.Owners); } )
.attr("cy", function (d) { return y(d.Metascores); } )
.attr("r", 5)
.style("fill", "#800000");
// new X axis
x.domain([-1000000000, 10000000000])
svg.select(".myXaxis")
.transition()
.duration(2000)
.attr("opacity", "1")
.call(d3.axisBottom(x));
svg.selectAll("circle")
.transition()
.delay(function(d,i){return(i*3)})
.duration(2000)
.attr("cx", function (d) { return x(d.Owners); } )
.attr("cy", function (d) { return y(d.Metascores); } )
//Create Axes Labels
svg.append('text')
.attr('transform', "rotate(-90)")
.attr('y', 10-margin.left)
.attr('x', 0-(height/2))
.attr('dy', "1em")
.attr('class', 'axisText')
.text("Metascore")
svg.append('text')
.attr('transform', `translate(${width/2}, ${height+50})`)
.attr('class','axisText')
.text('Number of Players')
})