using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using System.Drawing; using EgwCoreLib.Razor.Data; using System.Net.NetworkInformation; namespace EgwCoreLib.Razor { public partial class Chart { [Inject] protected IJSRuntime JSR { get; set; } = null!; #region Public Enums public enum ChartType { Pie, Bar, doughnut } #endregion Public Enums #region Public Properties [Parameter] public string[]? BackgroundColor { get; set; } [Parameter] public string[]? Data { get; set; } [Parameter] public string Id { get; set; } = "MyChart"; [Parameter] public string[]? Labels { get; set; } [Parameter] public ChartType Type { get; set; } #endregion Public Properties #region Protected Methods protected async Task InitDefault() { // Here we create an anonymous type with all the options that need to be sent to Chart.js var config = new { type = Type.ToString().ToLower(), options = new { responsive = true, scales = new { yAxes = new { suggestedMin = 0 } }, Animation = false }, data = new { datasets = new[] { new { data = Data, backgroundColor = BackgroundColor} }, labels = Labels } }; module = await JSR.InvokeAsync("import", "./_content/EgwCoreLib.Razor/Chart.razor.js"); await JSR.InvokeVoidAsync("setup", Id, config); } private IJSObjectReference? module; protected override async Task OnAfterRenderAsync(bool firstRender) { await InitDefault(); } #endregion Protected Methods } }