cash influx

master
Tomek Dubrownik 2013-08-21 22:39:22 +02:00
parent a0b4c75670
commit 2680322afb
1 changed files with 17 additions and 5 deletions

View File

@ -1,16 +1,23 @@
window.onload = function() {
var required = [], paid = [];
var required = [], paid = [], influx = [];
var today = new Date(),
year = 1900 + today.getYear(),
month = today.getMonth() + 1;
month = today.getMonth() + 1,
urlBase = 'https://kasownik.hackerspace.pl/api/';
for(i = 0; i < 12; ++i) {
var xhr = new XMLHttpRequest();
xhr.open("GET", 'https://kasownik.hackerspace.pl/api/month/' + year + '/' + month + '.json', false);
xhr.open("GET", urlBase + 'month/'+ year + '/' + month + '.json', false);
xhr.send();
var res = JSON.parse(xhr.response).content,
date = new Date(year, month, 1);
required.unshift({ x: date.getTime() / 1000, y: res.required });
paid.unshift({ x: date.getTime() / 1000, y: res.paid });
xhr = new XMLHttpRequest();
xhr.open("GET", urlBase + 'cashflow/'+ year + '/' + month + '.json', false);
xhr.send();
res = JSON.parse(xhr.response).content,
influx.unshift({ x: date.getTime() / 1000, y: res.in });
month -= 1;
if(month == 0) {
month = 12;
@ -18,7 +25,7 @@ window.onload = function() {
}
}
console.log(required, paid);
var palette = new Rickshaw.Color.Palette( { scheme: 'colorwheel' } );
var palette = new Rickshaw.Color.Palette( { scheme: 'munin' } );
var graph = new Rickshaw.Graph({
element: document.getElementById("plot"),
width: 800,
@ -35,7 +42,12 @@ window.onload = function() {
color: palette.color(),
data: paid,
name: 'Paid',
}
},
{
color: palette.color(),
data: influx,
name: 'Cash Influx',
},
]
});
graph.render();