55 lines
1.2 KiB
Plaintext
55 lines
1.2 KiB
Plaintext
@using EgwCoreLib.Razor.Data;
|
|
@using Microsoft.JSInterop;
|
|
|
|
<h3>Doughnut</h3>
|
|
|
|
@code {
|
|
[Inject]
|
|
private IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
|
|
public enum ChartType
|
|
{
|
|
Pie,
|
|
Bar,
|
|
Doughnut
|
|
}
|
|
|
|
//[Parameter]
|
|
public string Id { get; set; } = "myChart";
|
|
|
|
[Parameter]
|
|
public ChartType Type { get; set; }
|
|
|
|
[Parameter]
|
|
public double[] Data { get; set; } = null!;
|
|
[Parameter]
|
|
public List<DoughnutStyling> BackgroundColor { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public string[] Labels { get; set; } = null!;
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
var config = new
|
|
{
|
|
Type = Type.ToString().ToLower(),
|
|
Options = new
|
|
{
|
|
Responsive = true,
|
|
},
|
|
Data = new
|
|
{
|
|
Datasets = new[]
|
|
{
|
|
new { Data = Data, BackgroundColor = BackgroundColor.Select(x=>x.color), borderColor = BackgroundColor.Select(x=>x.border), borderWidth= 0, offset= 1, borderRadius = 0
|
|
}
|
|
},
|
|
Labels = Labels
|
|
}
|
|
};
|
|
|
|
await JSRuntime.InvokeVoidAsync("setup", Id, config);
|
|
}
|
|
}
|