39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
// 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();
|