Files
HomeAssistant/HomeAssistant.HistoryReplay/Components/Charts/PowerChart.razor
T
2026-06-28 13:58:35 +03:00

41 lines
1.8 KiB
Plaintext

@code {
[Parameter] public ReplayDataSeries? DataSeries { get; set; }
private List<ReplayDataPoint> TotalData => DataSeries?.GetSeries("Power", "TotalPower").ToList() ?? [];
private List<ReplayDataPoint> KnownData => DataSeries?.GetSeries("Power", "KnownDevices").ToList() ?? [];
private List<ReplayDataPoint> OtherData => DataSeries?.GetSeries("Power", "OtherPower").ToList() ?? [];
private ApexChartOptions<ReplayDataPoint> ChartOptions => new()
{
Chart = new Chart { Background = "transparent", ForeColor = "#adb5bd", Stacked = true },
Theme = new Theme { Mode = Mode.Dark },
Stroke = new Stroke { Width = 1 },
Xaxis = new XAxis { Type = XAxisType.Datetime },
Yaxis = [new YAxis { Title = new AxisTitle { Text = "Watts" }, DecimalsInFloat = 0 }],
Tooltip = new Tooltip { X = new TooltipX { Format = "HH:mm:ss" } },
Grid = new Grid { BorderColor = "#343a40" }
};
}
@if (TotalData.Count > 0)
{
<ApexChart TItem="ReplayDataPoint" Options="ChartOptions" Height="300">
<ApexPointSeries TItem="ReplayDataPoint"
Items="KnownData"
SeriesType="SeriesType.Area"
Name="Known Devices"
XValue="p => p.Timestamp.ToLocalTime().DateTime"
YValue="p => (decimal)p.Value" />
<ApexPointSeries TItem="ReplayDataPoint"
Items="OtherData"
SeriesType="SeriesType.Area"
Name="Other Power"
XValue="p => p.Timestamp.ToLocalTime().DateTime"
YValue="p => (decimal)p.Value" />
</ApexChart>
}
else
{
<div class="text-muted text-center py-4">No power data available</div>
}