-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgdp.js
82 lines (62 loc) · 3.86 KB
/
gdp.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
77
78
79
80
81
82
function callmepls(){
var margin = {top: 10, right: 30, bottom: 30, left: 60},
width = 1000 - margin.left - margin.right,
height = 950 - margin.top - margin.bottom;
// append the svg object to the body of the page
var svg = d3.select("#vis")
.select("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
// var svg2 = d3.select("#my_dataviz2")
// .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 + ")");
d3.csv("https://raw.githubusercontent.com/geetkalra/weblab/master/gdpPERcapita.csv")
.then(
function(data)
{
//X Axis
var x = d3.scaleLinear()
// .domain(d3.extent(data,d=>d.Year))
.domain(d3.extent(data, function(d){return d.date}))
.range([0,width]);
svg.append("g")
.attr("transform","translate(0," +height+")")
.call(d3.axisBottom(x).tickFormat(d3.format("d"))) // tickformat "d" helps to remove comma from year numbers if using Scale Linear
//Y Axis
var y = d3.scaleLinear()
.domain([0,7000])
// .domain(d3.extent(data, d=>d.India))
.range([height,0]);
svg.append("g")
.attr("transform", "translate(0,0)")
.call(d3.axisLeft(y))
// Actual path
var path = svg.append("path")
.attr("transform", "translate(0,0)")
.datum(data)
.attr("fill","none")
.attr("stroke","steelblue")
.attr("stroke-width",4)
.attr("d",d3.line()
.x(d=>x(d.date))
.y(d=>y(d.India))
)
// Variable to Hold Total Length
var totalLength = path.node().getTotalLength();
path
.attr("stroke-dasharray", totalLength + " " + totalLength)
.attr("stroke-dashoffset", totalLength)
.transition() // Call Transition Method
.duration(2000) // Set Duration timing (ms)
.ease(d3.easeLinear) // Set Easing option
.attr("stroke-dashoffset", 0); // Set final value of dash-offset for transition
}
)
}