diff --git a/src/apexcharts-card.ts b/src/apexcharts-card.ts index 3ccf1e3..ba7bbae 100644 --- a/src/apexcharts-card.ts +++ b/src/apexcharts-card.ts @@ -494,10 +494,13 @@ class ChartsCard extends LitElement { graphData = { series: this._graphs.flatMap((graph, index) => { if (!graph) return []; + let data = 0; if (graph.history.length === 0) { this._lastState[index] = null; + data = 0; } else { const lastState = graph.history[graph.history.length - 1][1]; + data = lastState === null ? 0 : lastState; this._lastState[index] = this._computeLastState(lastState, index); } if (!this._config?.series[index].show.in_chart) { @@ -508,15 +511,9 @@ class ChartsCard extends LitElement { } else { if (this._config?.chart_type === 'radialBar') { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - return [ - getPercentFromValue( - this._lastState[index] as number, - this._config.series[index].min, - this._config.series[index].max, - ), - ]; + return [getPercentFromValue(data, this._config.series[index].min, this._config.series[index].max)]; } else { - return [this._lastState[index]]; + return [data]; } } }), diff --git a/src/graphEntry.ts b/src/graphEntry.ts index 2ad12d1..9df86fa 100644 --- a/src/graphEntry.ts +++ b/src/graphEntry.ts @@ -1,7 +1,7 @@ import { HomeAssistant } from 'custom-card-helpers'; import { ChartCardSeriesConfig, EntityCachePoints, EntityEntryCache, HassHistory, HistoryBuckets } from './types'; import { compress, decompress, log } from './utils'; -import localForage, { config } from 'localforage'; +import localForage from 'localforage'; import { HassEntity } from 'home-assistant-js-websocket'; import { DateRange } from 'moment-range'; import { HOUR_24, moment } from './const';