// Initialize the echarts instance based on the prepared dom async function initMainChart() { const element = document.getElementById('main-chart') if (element === null) { return; } var myChart = echarts.init(element); try { const response = await fetch("/dashboard/main-chart"); 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' }) + '
' + 'Sum of Accounts: ' + params[0].data[1] + '
' + 'Sum of Savings: ' + params[1].data[1] + ' €' }; const chart = myChart.setOption(option); window.addEventListener('resize', function() { myChart.resize(); }); console.log("initialized main-chart"); } catch (error) { console.error(error.message); } } async function initTreasureChests() { const element = document.getElementById('treasure-chests') if (element === null) { return; } var myChart = echarts.init(element); try { const response = await fetch("/dashboard/treasure-chests"); if (!response.ok) { throw new Error(`Response status: ${response.status}`); } const option = await response.json(); const chart = myChart.setOption(option); window.addEventListener('resize', function() { myChart.resize(); }); console.log("initialized treasure-chests"); } catch (error) { console.error(error.message); } } initMainChart(); initTreasureChests();