Files
GPW/GPW.CORE.UI/Components/ChartHist.razor
T
2022-01-14 17:03:11 +01:00

69 lines
1.9 KiB
Plaintext

@inject IJSRuntime JSRuntime
<canvas id="@Id"></canvas>
@code {
[Parameter]
public string Id { get; set; } = "MyHist";
[Parameter]
public string[] Data { get; set; }
[Parameter]
public string[] Labels { get; set; }
[Parameter]
public string lineColor { get; set; }
[Parameter]
public string backColor { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender)
{
// creazione di un oggetto anonymous type con tutte le opzioni da passare a chart.js
var config = new
{
type = "bar",
options = new
{
Responsive = true,
scales = new
{
yAxes = new
{
display = true,
ticks = new
{
beginAtZero = true,
maxTicksLimit = 10
}
},
animation = new
{
duration = 100
}
}
},
data = new
{
datasets = new[]
{
new
{
data = Data,
borderColor = lineColor,
backgroundColor = backColor,
borderWidth = 1,
label= "Freq. Osservate"
}
},
labels = Labels
}
};
await JSRuntime.InvokeVoidAsync("setup", Id, config);
}
}
}