(() => {
let chart;
window.refreshHomeChart = async () => {
try {
const points = await EAR.api('/api/reports/trend?days=7');
const colors = ['#7e9c73','#d9bf75','#b2accb'];
const data = { labels: points.map(x => x.date.slice(5).replace('-','.')), datasets: ['mood','energy','stress'].map((key,i) => ({
label: ['心情','精力','压力'][i], data: points.map(x => x[key]), borderColor: colors[i], backgroundColor: colors[i],
tension: .35, pointRadius: 3, borderWidth: 2, spanGaps: false })) };
if(chart) { chart.data = data; chart.update(); return; }
chart = new Chart(document.getElementById('home-trend'), { type: 'line', data, options: { responsive: true, maintainAspectRatio: false,
plugins: { legend: { display: false } }, scales: { y: { min: 1, max: 5, ticks: { stepSize: 1, color:'#a5ad9c', font: { size:9 } }, grid: { color:'#f0f2e9' }, border: { display:false } }, x: { ticks: { color:'#a5ad9c', font:{size:9} }, grid: { display:false }, border: { display:false } } } } });
} catch(error) { EAR.toast(error.message, true); }
};
refreshHomeChart();
})();
(() => {
let chart;
window.refreshHomeChart = async () => {
try {
const points = await EAR.api('/api/reports/trend?days=7');
const colors = ['#7e9c73','#d9bf75','#b2accb'];
const data = { labels: points.map(x => x.date.slice(5).replace('-','.')), datasets: ['mood','energy','stress'].map((key,i) => ({
label: ['心情','精力','压力'][i], data: points.map(x => x[key]), borderColor: colors[i], backgroundColor: colors[i],
tension: .35, pointRadius: 3, borderWidth: 2, spanGaps: false })) };
if(chart) { chart.data = data; chart.update(); return; }
chart = new Chart(document.getElementById('home-trend'), { type: 'line', data, options: { responsive: true, maintainAspectRatio: false,
plugins: { legend: { display: false } }, scales: { y: { min: 1, max: 5, ticks: { stepSize: 1, color:'#a5ad9c', font: { size:9 } }, grid: { color:'#f0f2e9' }, border: { display:false } }, x: { ticks: { color:'#a5ad9c', font:{size:9} }, grid: { display:false }, border: { display:false } } } } });
} catch(error) { EAR.toast(error.message, true); }
};
refreshHomeChart();
})();