BlazorChartJS (1.0.2)
Published 2026-03-23 20:48:59 +00:00 by ptucci
Installation
dotnet nuget add source --name ptucci --username your_username --password your_token dotnet add package --source ptucci --version 1.0.2 BlazorChartJSAbout this package
A Blazor library for creating interactive charts using Chart.js
# BlazorChartJsLibrary
A lightweight Blazor wrapper for Chart.js (v4.4.3) with built-in chart selection and auto color palettes.
Latest tested working version
- 4.4.3
Overview
BlazorChartJsLibrary exposes three main Blazor chart components:
BarChartLineChartPieChart
It also ships with data set models and color palette factories.
Features
- Server-side and WASM Blazor support
- Chart.js auto-loading from CDN in JavaScript interop
- Auto color assignment out-of-the-box
- Optional chart title and axis titles (bar/line)
- Line smoothing with tension and interpolation mode
Installation
dotnet add package BlazorChartJs --source https://gitea.averainsights.com/api/packages/ptucci/nuget/index.json
Service registration
In Program.cs add:
using BlazorChartJsLibrary;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
// Registers default color palette provider
builder.Services.AddChartServices();
var app = builder.Build();
Usage examples
Bar chart
@using BlazorChartJsLibrary.Charts
@using BlazorChartJsLibrary.DataSets
<BarChart T=int Data="BarData" Labels="Labels" Title="Sales" XAxisTitle="Months" YAxisTitle="Units" />
@code {
private BarChartDataSet<int>[] BarData = new[] {
new BarChartDataSet<int> { Label = "Product A", Data = new[] { 10, 20, 30 } },
new BarChartDataSet<int> { Label = "Product B", Data = new[] { 5, 15, 25 } }
};
private string[] Labels = new[] { "Jan", "Feb", "Mar" };
}
Line chart
<LineChart T=int Data="LineData" Labels="Labels" Title="Trend" XAxisTitle="Month" YAxisTitle="Value" />
@code {
private LineChartDataSet<int>[] LineData = new[] {
new LineChartDataSet<int> { Label = "Series 1", Data = new[] { 3, 7, 3 }, Tension = 0.4m, CubicInterpolationMode = InterpolationMode.monotone }
};
private string[] Labels = new[] { "Jan", "Feb", "Mar" };
}
Pie chart
<PieChart Data="PieData" Labels="PieLabels" />
@code {
private string[] PieData = new[] { "45", "25", "30" };
private string[] PieLabels = new[] { "Apple", "Banana", "Cherry" };
}
Component details
ChartBasehandles JS interop and lazy Chart.js script loading.BarChartandLineChartrequireDataandLabelswith optionalTitle,XAxisTitle,YAxisTitle.PieChartrequiresDataandLabels; inverted indexing for slice colors is auto-applied.
Color palettes
Default palette is provided by DivergentSequentialColorPalette through AddChartServices(). You can swap IColorPaletteFactory registration for custom colors.
Notes
DataandLabelsare required for all chart types; null/empty triggersArgumentNullExceptionat render time.Chart.jsis loaded from CDN ashttps://cdn.jsdelivr.net/npm/chart.js@4.4.3/dist/chart.umd.min.js.
Contributing
- Fork the repo
- Add tests/examples under
BlazorChartJsLibrary/Examples - Submit PR with changelog in
README.txt
Dependencies
| ID | Version | Target Framework |
|---|---|---|
| Microsoft.AspNetCore.Components.Web | 10.0.5 | net10.0 |
| Microsoft.AspNetCore.Components.Web | 8.0.25 | net8.0 |
| Microsoft.AspNetCore.Components.Web | 9.0.14 | net9.0 |
Details
Assets (2)
Versions (3)
View all
blazorchartjs.1.0.2.nupkg
55 KiB
blazorchartjs.nuspec
1.2 KiB