forked from datatransparencylab/fingerprinting-census
-
Notifications
You must be signed in to change notification settings - Fork 0
/
draft_line_graph_ignore.html
94 lines (76 loc) · 2.27 KB
/
draft_line_graph_ignore.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
<script type="text/javascript">
function drawTrends1(){
// set the dimensions and margins of the graph
var margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
// parse the date / time, d3 built in format
var parseTime = d3.timeParse("%d-%b-%y");
// set the ranges
var x = d3.scaleTime().range([0, width]);
var y = d3.scaleLinear().range([height, 0]);
// define the line
var valueline = d3.line()
.x(function(d) { return x(d.date); console.log(d.date); })
.y(function(d) { return y(d.traffic); });
// append the svg obgect to the body of the page
// appends a 'group' element to 'svg'
// moves the 'group' element to the top left margin
var svgTrend1 = d3.select("#trend1").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 + ")");
var trend1data;
var scope="100000";
// Get the data
d3.csv("data.csv", function(error, data) {
if (error) throw error;
console.log(JSON.stringify(data));
// format the data
data.forEach(function(d) {
d.date = parseTime(d.date);
d.traffic = +d.traffic;
// console.log(d.date);
});
// Scale the range of the data
x.domain(d3.extent(data, function(d) { console.log(d.date); return d.date }));
y.domain([0, d3.max(data, function(d) { return d.traffic; })]);
// Add the valueline path.
svgTrend1.append("path")
.data([data])
.attr("class", "line")
.attr("d", valueline);
// Add the X Axis
svgTrend1.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x));
// Add the Y Axis
svgTrend1.append("g")
.call(d3.axisLeft(y));
console.log("done Drawing Line Chart Trends");
});
}
drawTrends1();
function createLabels(key) {
var monthDic = {
"01":"Jan",
"02":"Feb",
"03":"Mar",
"04":"Apr",
"05":"May",
"06":"Jun",
"07":"Jul",
"08":"Aug",
"09":"Sep",
"10":"Oct",
"11":"Nov",
"12":"Dec"
};
year = key.substring(0,4);
month = key.substring(4,6);
label = monthDic[month] + "'" + year.substring(2,4);
return label
}
</script>