//https://echarts.apache.org/examples/en/editor.html?c=dynamic-data2 var dom = document.getElementById('chart-container'); var myChart = echarts.init(dom, null, { renderer: 'canvas', useDirtyRect: false }); var app = {}; var option; function loadData() { now = new Date(+now + oneDay); value = value + Math.random() * 21 - 10; return { name: now.toString(), value: [ [now.getFullYear(), now.getMonth() + 1, now.getDate()].join('/'), Math.round(value) ] }; } let data = []; let now = new Date(1997, 9, 3); let oneDay = 24 * 3600 * 1000; let value = Math.random() * 1000; for (var i = 0; i < 20; i++) { data.push(loadData()); } option = { title: { text: 'Dynamic Data & Time Axis' }, tooltip: { trigger: 'axis', formatter: function (params) { params = params[0]; var date = new Date(params.name); return ( date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear() + ' : ' + params.value[1] ); }, axisPointer: { animation: false } }, xAxis: { type: 'time', splitLine: { show: false } }, yAxis: { type: 'value', boundaryGap: [0, '100%'], splitLine: { show: false } }, series: [ { name: 'Fake Data', type: 'line', showSymbol: false, data: data } ] }; async function fetchData() { const url = 'https://www.odooapi.it/Chargebull/api/usercount.php?token=a-1252a-9as-sa42-azx-aq235-1&mode=0&day=0&from=-10&to=-10'; try { const response = await fetch(url, { mode: 'no-cors' }); // Fetch with no-cors mode // Cannot use response.json() as the response is opaque // Handling opaque responses is limited console. console.log('Data fetched in no-cors mode, but cannot be read.'); return []; // Return empty as we can't process data } catch (error) { console.error('Failed to fetch data:', error); return []; } } setInterval(function () { for (var i = 0; i < 1; i++) { //data.shift(); //data.push(loadData()); let lastIndex = data.length - 1; data[lastIndex].name = "2024-12-2"; // Example: Changing the name data[lastIndex].value = [data[lastIndex].value[0],data[lastIndex].value[1] + Math.round( Math.random() * 21 - 10)]; // Example: Changing the value //data[lastIndex].value = ["2024-08-07",55] } myChart.setOption({ series: [ { data: data } ] }); }, 1000);