mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 07:16:39 +00:00
Fix statistics bar chart time axis (#18450)
This commit is contained in:
parent
c3d809fcf3
commit
c5a0a5bbbf
@ -134,7 +134,7 @@ _adapters._date.override({
|
||||
this.options.config
|
||||
);
|
||||
case "week":
|
||||
return formatDate(
|
||||
return formatDateVeryShort(
|
||||
new Date(time),
|
||||
this.options.locale,
|
||||
this.options.config
|
||||
|
@ -73,6 +73,8 @@ export class StatisticsChart extends LitElement {
|
||||
|
||||
@property({ type: Boolean }) public isLoadingData = false;
|
||||
|
||||
@property() public period?: string;
|
||||
|
||||
@state() private _chartData: ChartData = { datasets: [] };
|
||||
|
||||
@state() private _statisticIds: string[] = [];
|
||||
@ -92,7 +94,12 @@ export class StatisticsChart extends LitElement {
|
||||
}
|
||||
|
||||
public willUpdate(changedProps: PropertyValues) {
|
||||
if (!this.hasUpdated || changedProps.has("unit")) {
|
||||
if (
|
||||
!this.hasUpdated ||
|
||||
changedProps.has("unit") ||
|
||||
changedProps.has("period") ||
|
||||
changedProps.has("chartType")
|
||||
) {
|
||||
this._createOptions();
|
||||
}
|
||||
if (
|
||||
@ -160,6 +167,7 @@ export class StatisticsChart extends LitElement {
|
||||
},
|
||||
},
|
||||
ticks: {
|
||||
source: this.chartType === "bar" ? "data" : undefined,
|
||||
maxRotation: 0,
|
||||
sampleSize: 5,
|
||||
autoSkipPadding: 20,
|
||||
@ -173,6 +181,12 @@ export class StatisticsChart extends LitElement {
|
||||
},
|
||||
time: {
|
||||
tooltipFormat: "datetime",
|
||||
unit:
|
||||
this.chartType === "bar" &&
|
||||
this.period &&
|
||||
["hour", "day", "week", "month"].includes(this.period)
|
||||
? this.period
|
||||
: undefined,
|
||||
},
|
||||
},
|
||||
y: {
|
||||
|
@ -193,6 +193,7 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
||||
.isLoadingData=${!this._statistics}
|
||||
.statisticsData=${this._statistics}
|
||||
.metadata=${this._metadata}
|
||||
.period=${this._config.period}
|
||||
.chartType=${this._config.chart_type || "line"}
|
||||
.statTypes=${this._statTypes!}
|
||||
.names=${this._names}
|
||||
|
Loading…
x
Reference in New Issue
Block a user