-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.js
84 lines (79 loc) · 1.8 KB
/
plot.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
83
84
$(window).load(function () {
$.getJSON('./cursed-plot.json', function (data) {
$("#loadprogress").hide();
/*var rent = data.map(item => { return { y: item.mp, x: new Date(item.dt) / 1000.0 } });
var others = data.map(item => { return { y: item.mr, x: new Date(item.dt) / 1000.0 } });
var sum = data.map(item => { return { y: item.mr + item.mp, x: new Date(item.dt) / 1000.0 } });*/
const chart = c3.generate({
bindto: '#chart',
data: {
x: 'x',
columns: [
['x', ...data.map(item => new Date(item.dt))],
['rent', ...data.map(item => Number(item.mp))],
['incomes', ...data.map(item => Number(item.mi))],
['others', ...data.map(item => Number(item.mr))],
['saldo', ...data.map(item => Number(item.sld))],
['sum', ...data.map(item => Number(item.mp) + Number(item.mr) + Number(item.mi))]
// ['rolling', ...data.map(item=>item.sum)],
],
names: {
'rent': 'Rent, heating, power',
'incomes': 'Incomes (memberships & other)',
'others': 'Other expenses',
'sum': 'Monthly balance',
'saldo': 'Saldo',
},
axes: {
'rent': 'y',
'incomes': 'y',
'others': 'y',
'sum': 'y',
'saldo': 'y2'
},
groups: [
['rent', 'incomes', 'others']
],
type: 'bar',
types: {
sum: 'line',
saldo: 'line'
},
},
// subchart: {
// show: true
// },
grid: {
y: {
lines: [{
value: 0
}, ],
},
},
axis: {
x: {
type: 'timeseries',
tick: {
format: '%Y-%m'
}
},
y: {
tick: {
format: function (d) {
return d3.format(",.2f")(d) + " zł";
}
}
},
y2: {
show: true,
tick: {
format: function (d) {
return d3.format(",.2f")(d) + " zł";
}
}
}
}
});
//
});
});