UI_SequentMicrosystems-RPI/Components/RTD8TMGraphComponent.razor

98 lines
2.7 KiB
Plaintext
Raw Permalink Normal View History

2023-12-17 17:09:39 +00:00
@using ApexCharts
2024-02-01 07:33:05 +00:00
@using Newtonsoft.Json
2023-12-17 17:09:39 +00:00
@using UI_SequentMicrosystems.Components
@using UI_SequentMicrosystems.Services
@using UI_SequentMicrosystems.Models
@inject RTD8TMService _RTD8TMService
2024-02-01 07:33:05 +00:00
@if (_RTD8TMService.GetActualData().Keys.Count > 0)
{
if (false)
2023-12-17 17:09:39 +00:00
{
2024-02-01 07:33:05 +00:00
<div>
<input type="text" class="form-control form-control-sm bg-black text-white no-border" placeholder="Json syntax with Chart Points" @onchange="((x) => ChartPointsAdd(x.Value.ToString()))">
</div>
}
<ApexChart TItem="RTD8TMPointModel"
Title="Temperature"
Options="chartOptions"
@ref="chart">
@foreach (byte stack in _RTD8TMService.GetActualData().Keys)
2023-12-17 17:09:39 +00:00
{
2024-02-01 07:33:05 +00:00
for (byte chanel = 0; chanel < 8; chanel++)
2023-12-17 17:09:39 +00:00
{
2024-02-01 07:33:05 +00:00
if (_RTD8TMService.GetChanelName(stack, chanel) != "----------")
{
//Console.WriteLine($"Chart Data: Stack: {stack} | Chanel: {chanel} | {JsonConvert.SerializeObject(_RTD8TMService.GetChartData(stack, chanel))}");
<ApexPointSeries TItem="RTD8TMPointModel"
Items="@_RTD8TMService.GetChartData(stack, chanel)"
Name="@(_RTD8TMService.GetChanelName(stack, chanel))"
SeriesType="SeriesType.Line"
XValue="@(e => e.Time.ToString("HH:mm:ss"))"
YValue="@(e => (decimal)e.Value)"
OrderBy="e=>e.X" />
}
2023-12-17 17:09:39 +00:00
}
}
2024-02-01 07:33:05 +00:00
</ApexChart>
}
2023-12-17 17:09:39 +00:00
@code {
private ApexChart<RTD8TMPointModel> chart;
private ApexChartOptions<RTD8TMPointModel> chartOptions;
2023-12-17 17:09:39 +00:00
protected override void OnInitialized()
{
_RTD8TMService.EventUpdateGraph += UpdateChart;
chartOptions = new ApexChartOptions<RTD8TMPointModel>
2023-12-17 17:09:39 +00:00
{
2024-02-01 07:33:05 +00:00
Theme = new Theme
{
Mode = Mode.Dark,
},
Legend = new Legend
{
Position = LegendPosition.Bottom,
FontSize = "15px",
HorizontalAlign = Align.Center
}
};
2023-12-17 17:09:39 +00:00
}
public async Task UpdateChart(object? o, bool b)
{
await InvokeAsync(() =>
{
chart.UpdateSeriesAsync(false);
StateHasChanged();
});
}
2024-02-01 07:33:05 +00:00
public void ChartPointsAdd(string points)
{
_RTD8TMService.SetChartData(JsonConvert.DeserializeObject<SortedList<byte, List<List<RTD8TMPointModel>>>>(points));
}
2023-12-17 17:09:39 +00:00
}