-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Graphs to Statistics tab #1011
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
function createGraphs(members_stats, monthly_stats) { | ||
let names = []; | ||
let balance = []; | ||
let colors = []; | ||
for (let i = 0; i < members_stats.length; i++) { | ||
names = names.concat(members_stats[i].member.name) | ||
balance = balance.concat(members_stats[i].balance) | ||
if(members_stats[i].balance < 0){ | ||
colors = colors.concat('rgba(255, 0, 0, .5)') | ||
} | ||
else{ | ||
colors = colors.concat('rgba(0, 128, 0, .5)') | ||
} | ||
} | ||
|
||
let spent = []; | ||
let month = []; | ||
for (const [year, month1] of Object.entries(monthly_stats)) { | ||
for (const [month2, value] of Object.entries(month1)) { | ||
spent = spent.concat(value); | ||
month = month.concat(month2); | ||
} | ||
} | ||
month = month.slice(-12); | ||
spent = spent.slice(-12); | ||
for (let i = 0; i < month.length; i++) { | ||
if(month[i] == 1){ | ||
month[i] = 'Jan'; | ||
} | ||
else if(month[i] == 2){ | ||
month[i] = 'Feb'; | ||
} | ||
else if(month[i] == 3){ | ||
month[i] = 'Mar'; | ||
} | ||
else if(month[i] == 4){ | ||
month[i] = 'Apr'; | ||
} | ||
else if(month[i] == 5){ | ||
month[i] = 'May'; | ||
} | ||
else if(month[i] == 6){ | ||
month[i] = 'June'; | ||
} | ||
else if(month[i] == 7){ | ||
month[i] = 'July'; | ||
} | ||
else if(month[i] == 8){ | ||
month[i] = 'Aug'; | ||
} | ||
else if(month[i] == 9){ | ||
month[i] = 'Sept'; | ||
} | ||
else if(month[i] == 10){ | ||
month[i] = 'Oct'; | ||
} | ||
else if(month[i] == 11){ | ||
month[i] = 'Nov'; | ||
} | ||
else if(month[i] == 12){ | ||
month[i] = 'Dec'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means that it isn't translatable. Any idea on how we could achieve this? |
||
} | ||
} | ||
|
||
|
||
const ctx = document.getElementById('balance').getContext('2d'); | ||
const myChart = new Chart(ctx, { | ||
type: 'bar', | ||
data: { | ||
labels: names, | ||
datasets: [{ | ||
label: '', | ||
data: balance, | ||
backgroundColor: colors, | ||
borderColor: colors, | ||
borderWidth: 1 | ||
}] | ||
}, | ||
options: { | ||
scales: { | ||
y: { | ||
beginAtZero: true | ||
} | ||
}, | ||
title: { | ||
display: true, | ||
text: 'Balance', | ||
fontSize: 25, | ||
fontColor: 'rgb(0,0,0)' | ||
}, | ||
legend:{ | ||
display: false | ||
}, | ||
scales: { | ||
xAxes: [{ | ||
ticks: { | ||
fontSize: 15 | ||
} | ||
}] | ||
}, | ||
responsive: false | ||
|
||
} | ||
}); | ||
|
||
const chart2 = document.getElementById('monthlySpending').getContext('2d'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could rename this |
||
const myChart2 = new Chart(chart2, { | ||
type: 'line', | ||
data: { | ||
labels: month, | ||
datasets: [{ | ||
label: '', | ||
data: spent, | ||
fill: false, | ||
lineTension: .1, | ||
borderColor: 'rgb(128,128,128)' | ||
}] | ||
}, | ||
options: { | ||
title: { | ||
display: true, | ||
text: 'Expenses Per Month in the Past Year', | ||
fontSize: 25, | ||
fontColor: 'rgb(0,0,0)' | ||
}, | ||
legend:{ | ||
display: false | ||
}, | ||
responsive: false | ||
} | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,12 @@ <h2>{{ _("Expenses by Month") }}</h2> | |
{% endfor %} | ||
</tbody> | ||
</table> | ||
<h2>Graphs</h2> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should make this translatable. |
||
<canvas id="balance" height="400"></canvas> | ||
<canvas id="monthlySpending" height="400"></canvas> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about the fixed width: what happens when we view this from a mobile for instance? |
||
<script> | ||
createGraphs({{ members_stats|tojson }}, {{ monthly_stats|tojson }}); | ||
</script> | ||
</div> | ||
|
||
{% endblock %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably use a
for…in
statement instead.