Fix statistics graph (#9607)

This commit is contained in:
Bram Kragten 2021-07-27 00:03:31 +02:00 committed by GitHub
parent 586fa1d0f0
commit f459abdf85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -267,7 +267,12 @@ class StatisticsChart extends LitElement {
stats.forEach((stat) => { stats.forEach((stat) => {
const dataValues: Array<number | null> = []; const dataValues: Array<number | null> = [];
statTypes.forEach((type) => { statTypes.forEach((type) => {
const val = stat[type]; let val: number | null;
if (type === "sum") {
val = stat.state;
} else {
val = stat[type];
}
dataValues.push(val !== null ? Math.round(val * 100) / 100 : null); dataValues.push(val !== null ? Math.round(val * 100) / 100 : null);
}); });
const date = new Date(stat.start); const date = new Date(stat.start);

View File

@ -146,7 +146,10 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
return; return;
} }
const startDate = new Date(); const startDate = new Date();
startDate.setHours(-24 * (this._config!.days_to_show || 30)); startDate.setTime(
startDate.getTime() -
1000 * 60 * 60 * (24 * (this._config!.days_to_show || 30) + 1)
);
this._fetching = true; this._fetching = true;
try { try {
this._statistics = await fetchStatistics( this._statistics = await fetchStatistics(