AstrolChart<TItem> es el contenedor de la gráfica y dentro se colocan una o varias series. Cada serie recibe una lista de objetos de su aplicación (Items) y unas funciones que dicen qué valor va en cada eje. No hay que preparar arrays ni JSON: se trabaja con sus propias clases y LINQ.
@using AstrolCharts @* 1. A chart (AstrolChart) with the type of your data (TItem). 2. One or more series: which items (Items), what goes on X (XValue) and on Y (YValue). 3. SeriesType chooses how it is drawn: Bar, Line, Area, Pie, Donut... *@<AstrolChart TItem="Sale" Title="Sales by month"> <AstrolPointSeries TItem="Sale" Items="sales" Name="Sales" SeriesType="SeriesType.Bar" XValue="e => e.Month" YValue="e => e.Amount" /></AstrolChart> @code { private readonly List<Sale> sales = new() { new() { Month = "Jan", Amount = 120 }, new() { Month = "Feb", Amount = 180 }, new() { Month = "Mar", Amount = 150 }, new() { Month = "Apr", Amount = 210 }, }; public class Sale { public string Month { get; set; } = string.Empty; public decimal Amount { get; set; } }}Todo el aspecto se configura con Options (AstrolChartOptions<TItem>). Sus propiedades siguen exactamente la documentación de opciones de ApexCharts con nombres de C#: Chart (apilado, zoom, barra de herramientas, animaciones), Colors, Stroke (grosor y curva), Fill, Markers, DataLabels, Legend, Tooltip, Xaxis, Yaxis (varios ejes), Grid, PlotOptions (por tipo: Bar, Pie, RadialBar, Heatmap, Treemap...), Annotations, Theme y Responsive. Cree las opciones una vez (un campo) y no en cada render.
private readonly AstrolChartOptions<Sale> options = new(){ Chart = new Chart { Stacked = true, Toolbar = new Toolbar { Show = false } }, Colors = new List<string> { "#ffd800", "#007bff" }, Stroke = new Stroke { Curve = Curve.Smooth, Width = 3 }, DataLabels = new DataLabels { Enabled = true }, Legend = new Legend { Position = LegendPosition.Bottom }, PlotOptions = new PlotOptions { Bar = new PlotOptionsBar { Horizontal = true, BorderRadius = 4 } }, Xaxis = new XAxis { Title = new AxisTitle { Text = "Month" } }, Yaxis = new List<YAxis> { new YAxis { Title = new AxisTitle { Text = "Amount" } } }, Tooltip = new Tooltip { Shared = true, Intersect = false },}; // <AstrolChart TItem="Sale" Options="options"> ... </AstrolChart>AstrolChart<TItem>:
Con @ref (private AstrolChart<Sale>? chart;):