-
Notifications
You must be signed in to change notification settings - Fork 2
/
graph.js
66 lines (57 loc) · 1.72 KB
/
graph.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
transactionsData.forEach(function(d) {
d.date = parseDate(d.date);
console.log(d.date);
});
let dateDim = ndx.dimension(dc.pluck("date"));
let minDate = dateDim.bottom(1)[0].date;
let maxDate = dateDim.top(1)[0].date;
let tomSpend = dateDim.group().reduceSum(function(d) {
if (d.name === "Tom") {
return +d.spend;
//the plus sign forces the return to be a nº
}
else {
return 0;
}
});
let aliceSpend = dateDim.group().reduceSum(function(d) {
if (d.name === "Alice") {
return +d.spend;
//the plus sign forces the return to be a nº
}
else {
return 0;
}
});
let bobSpend = dateDim.group().reduceSum(function(d) {
if (d.name === "Bob") {
return +d.spend;
//the plus sign forces the return to be a nº
}
else {
return 0;
}
});
let compositeChart = dc.compositeChart("#composite-chart")
compositeChart
.width(1000)
.height(200)
.dimension(dateDim)
.x(d3.time.scale().domain([minDate, maxDate]))
.yAxisLabel("Spend")
.legend(dc.legend().x(80).y(20).itemHeight(13).gap(5))
.renderHorizontalGridLines(true)
.compose([
dc.lineChart(compositeChart)
.colors("lightgreen")
.group(tomSpend, "Tom"),
dc.lineChart(compositeChart)
.colors("violet")
.group(bobSpend, "Bob"),
dc.lineChart(compositeChart)
.colors("indigo")
.group(aliceSpend, "Alice")
])
.render()
.yAxis().ticks(4);
dc.renderAll();