Fix statistics bar chart time axis (#18450)

This commit is contained in:
karwosts 2023-10-30 05:39:15 -07:00 committed by GitHub
parent c3d809fcf3
commit c5a0a5bbbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 2 deletions

View File

@ -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

View File

@ -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: {

View File

@ -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}