66 lines
1.5 KiB
C#
66 lines
1.5 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using MP.Data;
|
|
|
|
namespace MP.SPEC.Components.Chart
|
|
{
|
|
public partial class Doughnut
|
|
{
|
|
[Inject]
|
|
private IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
|
|
public enum ChartType
|
|
{
|
|
Pie,
|
|
Bar,
|
|
Doughnut
|
|
}
|
|
|
|
[Parameter]
|
|
public string Id { get; set; }
|
|
|
|
[Parameter]
|
|
public ChartType Type { get; set; }
|
|
|
|
[Parameter]
|
|
public double[] Data { get; set; }
|
|
|
|
[Parameter]
|
|
public string[] BackgroundColor { get; set; }
|
|
|
|
[Parameter]
|
|
public string[] Labels { get; set; }
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
var config = new
|
|
{
|
|
Type = Type.ToString().ToLower(),
|
|
Options = new
|
|
{
|
|
Responsive = true,
|
|
Scales = new
|
|
{
|
|
YAxes = new[]
|
|
{
|
|
new { Ticks = new {
|
|
BeginAtZero=true
|
|
} }
|
|
}
|
|
}
|
|
},
|
|
Data = new
|
|
{
|
|
Datasets = new[]
|
|
{
|
|
new { Data = Data, BackgroundColor = BackgroundColor}
|
|
},
|
|
Labels = Labels
|
|
}
|
|
};
|
|
|
|
await JSRuntime.InvokeVoidAsync("setup", Id, config);
|
|
}
|
|
}
|
|
} |