feat(dashboard): #82 add chart for sum of account and savings
This commit was merged in pull request #190.
This commit is contained in:
38
static/js/dashboard.js
Normal file
38
static/js/dashboard.js
Normal file
@@ -0,0 +1,38 @@
|
||||
// Initialize the echarts instance based on the prepared dom
|
||||
|
||||
async function init() {
|
||||
const element = document.getElementById('graph')
|
||||
if (element === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var myChart = echarts.init(element);
|
||||
|
||||
try {
|
||||
const response = await fetch("/dashboard/dataset");
|
||||
if (!response.ok) {
|
||||
throw new Error(`Response status: ${response.status}`);
|
||||
}
|
||||
|
||||
const option = await response.json();
|
||||
option.tooltip.formatter = function (params) {
|
||||
return new Date(params[0].data[0]).toLocaleString([], { day: 'numeric', month: 'short', year: 'numeric' }) +
|
||||
'<br />' +
|
||||
'Sum of Accounts: <span class="font-bold">' + params[0].data[1] + '</span> € <br />' +
|
||||
'Sum of Savings: <span class="font-bold">' + params[1].data[1] + '</span> €'
|
||||
};
|
||||
|
||||
const chart = myChart.setOption(option);
|
||||
window.addEventListener('resize', function() {
|
||||
myChart.resize();
|
||||
});
|
||||
|
||||
console.log("initialized charts");
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
}
|
||||
|
||||
// Display the chart using the configuration items and data just specified.
|
||||
}
|
||||
|
||||
init();
|
||||
@@ -4,7 +4,6 @@ htmx.on("htmx:afterSwap", () => {
|
||||
});
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
console.log("DOMContentLoaded");
|
||||
updateTime(document);
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user