Path: redb-identity/src/redb.Identity.Web/Components/Shared/RdbChart.razor
Snapshot: redb-identity, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-identity
Page: https://redbase.app/src/dev-2026-12-06/redb-identity/src/redb.Identity.Web/Components/Shared/RdbChart.razor
----
@using Microsoft.JSInterop
@inject IJSRuntime JS
@implements IAsyncDisposable
@code {
[Parameter, EditorRequired] public string ChartId { get; set; } = default!;
[Parameter] public int? Height { get; set; }
private string _canvasId => $"chart-{ChartId}";
public async Task CreateLineAsync(string[] labels, ChartDataset[] datasets, string? yAxisLabel = null)
{
await JS.InvokeVoidAsync("tsakCharts.createLine", _canvasId, labels, datasets, yAxisLabel);
}
///
/// Creates an area chart (line with fill) with the given labels and datasets.
///
public async Task CreateAreaAsync(string[] labels, ChartDataset[] datasets, string? yAxisLabel = null)
{
await JS.InvokeVoidAsync("tsakCharts.createArea", _canvasId, labels, datasets, yAxisLabel);
}
///
/// Creates a bar chart with the given labels and datasets.
///
public async Task CreateBarAsync(string[] labels, ChartDataset[] datasets, string? yAxisLabel = null)
{
await JS.InvokeVoidAsync("tsakCharts.createBar", _canvasId, labels, datasets, yAxisLabel);
}
///
/// Creates a donut chart with the given labels, values and colors.
///
public async Task CreateDonutAsync(string[] labels, double[] data, string[] colors)
{
await JS.InvokeVoidAsync("tsakCharts.createDonut", _canvasId, labels, data, colors);
}
///
/// Updates chart data without recreating it.
///
public async Task UpdateAsync(string[] labels, ChartDataset[] datasets)
{
await JS.InvokeVoidAsync("tsakCharts.update", _canvasId, labels, datasets);
}
public async ValueTask DisposeAsync()
{
try
{
await JS.InvokeVoidAsync("tsakCharts.destroy", _canvasId);
}
catch (JSDisconnectedException) { }
catch (JSException) { }
catch (InvalidOperationException) { }
}
public record ChartDataset(string Label, double[] Data, string BorderColor, string? BackgroundColor = null);
}