diff --git a/src/components/chart/statistics-chart.ts b/src/components/chart/statistics-chart.ts index 89c6905eac5f..164637fc4188 100644 --- a/src/components/chart/statistics-chart.ts +++ b/src/components/chart/statistics-chart.ts @@ -71,6 +71,8 @@ export class StatisticsChart extends LitElement { @property({ type: Boolean }) public hideLegend = false; + @property({ type: Boolean }) public logarithmicScale = false; + @property({ type: Boolean }) public isLoadingData = false; @property() public period?: string; @@ -98,7 +100,8 @@ export class StatisticsChart extends LitElement { !this.hasUpdated || changedProps.has("unit") || changedProps.has("period") || - changedProps.has("chartType") + changedProps.has("chartType") || + changedProps.has("logarithmicScale") ) { this._createOptions(); } @@ -198,6 +201,7 @@ export class StatisticsChart extends LitElement { display: unit || this.unit, text: unit || this.unit, }, + type: this.logarithmicScale ? "logarithmic" : "linear", }, }, plugins: { diff --git a/src/panels/lovelace/cards/hui-statistics-graph-card.ts b/src/panels/lovelace/cards/hui-statistics-graph-card.ts index 691123ab7d3f..a70785bfa731 100644 --- a/src/panels/lovelace/cards/hui-statistics-graph-card.ts +++ b/src/panels/lovelace/cards/hui-statistics-graph-card.ts @@ -199,6 +199,7 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard { .names=${this._names} .unit=${this._unit} .hideLegend=${this._config.hide_legend || false} + .logarithmicScale=${this._config.logarithmic_scale || false} > diff --git a/src/panels/lovelace/cards/types.ts b/src/panels/lovelace/cards/types.ts index f895961a4e79..e83e1f620cca 100644 --- a/src/panels/lovelace/cards/types.ts +++ b/src/panels/lovelace/cards/types.ts @@ -328,6 +328,7 @@ export interface StatisticsGraphCardConfig extends LovelaceCardConfig { stat_types?: StatisticType | StatisticType[]; chart_type?: "line" | "bar"; hide_legend?: boolean; + logarithmic_scale?: boolean; } export interface StatisticCardConfig extends LovelaceCardConfig { diff --git a/src/panels/lovelace/editor/config-elements/hui-statistics-graph-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-statistics-graph-card-editor.ts index 3ed3b6d8afc4..71f77a86bf7f 100644 --- a/src/panels/lovelace/editor/config-elements/hui-statistics-graph-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-statistics-graph-card-editor.ts @@ -72,6 +72,7 @@ const cardConfigStruct = assign( stat_types: optional(union([array(statTypeStruct), statTypeStruct])), unit: optional(string()), hide_legend: optional(boolean()), + logarithmic_scale: optional(boolean()), }) ); @@ -211,6 +212,11 @@ export class HuiStatisticsGraphCardEditor required: false, selector: { boolean: {} }, }, + { + name: "logarithmic_scale", + required: false, + selector: { boolean: {} }, + }, ], }, ]; @@ -347,6 +353,7 @@ export class HuiStatisticsGraphCardEditor case "period": case "unit": case "hide_legend": + case "logarithmic_scale": return this.hass!.localize( `ui.panel.lovelace.editor.card.statistics-graph.${schema.name}` ); diff --git a/src/resources/chartjs.ts b/src/resources/chartjs.ts index 1a39fb4b5e59..fc5b44411c04 100644 --- a/src/resources/chartjs.ts +++ b/src/resources/chartjs.ts @@ -12,6 +12,7 @@ import { Chart, BarElement, BarController, + LogarithmicScale, } from "chart.js"; import { TextBarElement } from "../components/chart/timeline-chart/textbar-element"; import { TimelineController } from "../components/chart/timeline-chart/timeline-controller"; @@ -35,5 +36,6 @@ Chart.register( TextBarElement, TimeLineScale, TimelineController, - CategoryScale + CategoryScale, + LogarithmicScale ); diff --git a/src/translations/en.json b/src/translations/en.json index 20e3ad35d3e3..ac95bf09e79c 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4997,7 +4997,8 @@ }, "pick_statistic": "Add a statistic", "picked_statistic": "Statistic", - "hide_legend": "Hide legend" + "hide_legend": "Hide legend", + "logarithmic_scale": "Logarithmic scale" }, "statistic": { "name": "Statistic",