/
movies_scatter.html
94 lines (73 loc) · 2.51 KB
/
movies_scatter.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
93
94
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Movies Scatter</title>
<script src="https://d3js.org/d3.v5.min.js"></script>
</head>
<body>
<div id="chart"></div>
<p>Podemos ver que não há uma correlação entre o orçamento de um filme e sua bilheteria.<br/>
O preço da bilheteria praticamente não mudou, porém o filme Avatar, com um dos maiores orçamentos, conseguiu superar em muito a bilheteria dos outros filmes </p>
<script type="text/javascript">
d3.json("data/movies.json").then(function(dataset){
let margin = {top: 40, right: 40, bottom: 40, left: 40};
let w = 800 - margin.left - margin.right;
let h = 300 - margin.top - margin.bottom;
let svg = d3.select("#chart")
.append("svg")
.attr("width", w + margin.left + margin.right)
.attr("height", h + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
let xScale = d3.scaleLinear()
.domain([0, d3.max(dataset, function(d){
return d.Budget_M
})])
.range([0,w])
let xAxis = d3.axisBottom()
.scale(xScale)
.ticks(5)
let yScale = d3.scaleLinear()
.domain([0, d3.max(dataset, function(d){
return d.Worldwide_Gross_M
})])
.range([h,0])
let yAxis = d3.axisLeft()
.scale(yScale)
.ticks(5)
svg.selectAll("circle")
.data(dataset)
.enter()
.append("circle")
.attr("cx", function(d){
return xScale(d.Budget_M)
})
.attr("cy", function(d){
return yScale(d.Worldwide_Gross_M)
})
.attr("r", 5)
svg.append("g")
.attr("transform", "translate(0,"+h+")")
.call(xAxis);
svg.append("g")
.call(yAxis);
svg.append("text")
.attr("transform", "translate(" + (w/2) + "," + (h + margin.bottom) + ")")
.style("text-anchor", "middle")
.attr("font-family", "sans-serif")
.attr("font-size", "12px")
.text("Orçamento");
svg.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 0 - margin.left)
.attr("x",0 - (h / 2))
.attr("dy", "1em")
.style("text-anchor", "middle")
.attr("font-family", "sans-serif")
.attr("font-size", "12px")
.text("Bilheteria");
});
</script>
</body>
</html>