WeldProcessRecordPage.razor 1.27 KB
@using DataAcquisition.DataAccess
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<DataContext> dbContextFactory;

<AntDesign.Charts.Line Data="data" Config="config" />

@code {
    [Parameter]
    public Guid ProductionId { get; set; }

    IEnumerable<object> data = new List<object>();

    protected override void OnParametersSet()
    {
        using var context = dbContextFactory.CreateDbContext();
        data = context.WeldProcessRecords.Where(x => x.ProductionId == ProductionId).OrderBy(x => x.CreateTime).ThenBy(x => x.Code).Select(x => new
        {
            x.CreateTime,
            x.Name,
            x.Value
        }).AsEnumerable().Select(x =>
        {
            double.TryParse(x.Value, out var val);
            var data = new
            {
                Time = x.CreateTime.ToString("HH:mm:ss"),
                x.Name,
                Value = Math.Round(val, 1)
            };
            return data;
        }).ToList();
        base.OnParametersSet();
    }

    LineConfig config = new LineConfig
        {
            Padding = "auto",
            XField = "time",
            YField = "value",
            YAxis = new ValueAxis
            {
                Label = new BaseAxisLabel()
            },
            SeriesField = "name"
        };
}