Kebechet.Blazor.ChartJS
4.3.0.8
Prefix Reserved
dotnet add package Kebechet.Blazor.ChartJS --version 4.3.0.8
NuGet\Install-Package Kebechet.Blazor.ChartJS -Version 4.3.0.8
<PackageReference Include="Kebechet.Blazor.ChartJS" Version="4.3.0.8" />
<PackageVersion Include="Kebechet.Blazor.ChartJS" Version="4.3.0.8" />
<PackageReference Include="Kebechet.Blazor.ChartJS" />
paket add Kebechet.Blazor.ChartJS --version 4.3.0.8
#r "nuget: Kebechet.Blazor.ChartJS, 4.3.0.8"
#:package Kebechet.Blazor.ChartJS@4.3.0.8
#addin nuget:?package=Kebechet.Blazor.ChartJS&version=4.3.0.8
#tool nuget:?package=Kebechet.Blazor.ChartJS&version=4.3.0.8
Blazor.ChartJS
This repo contains lean wrapper around Chart.js for Blazor.
Motivation:
Repository ChartJs.Blazor is no longer maintained
and also it is stuck at old version chart.js@2.9.4.
The lack of maintainers is quite often problem.
Thats why I have created the leanest wrapper possible.
This should be quite future proof and if needed also a beginner should be able to bump chart.js to newer version or fix potential bug in the wrapper.
Versioning
chart.jsversion is part of the package version.- examples:
- package version
4.3.0.0means thatchart.jsversion used is4.3.0 - package version
4.3.0.2means thatchart.jsversion used is4.3.0and we did 2 bugfixes/improvements in the wrapper
- package version
ChartJS custom changes
- we use
chart.jsversion:4.3.1BUT we have added one extra fix that is not yet merged intochart.js masterrepo. - Bugs fixed by PR #11132 are #10932, #11089
- after this PR is merged to master we will fallback to
chart.jsmaster branch
Usage example
- our wrapper contains methods:
createChart,getChart,updateChart,clearChartData,destroyChart - all data and configurations are provided as anonymous objects. Thats why it should be 1:1 with chart.js docs
Index.razor
@using Blazor.ChartJS
<Chart @ref="_chart" Config="_config" OnChartInitialized="() => _isInitializing = false" />
Index.razor.cs
using Blazor.ChartJS;
namespace BlazorChartTest.Pages;
public partial class Index
{
private Chart? _chart { get; set; }
private bool _isInitializing = true;
private readonly dynamic _config = new
{
Type = "line",
Data = new
{
Labels = new[] { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" },
Datasets = new[]
{
new
{
Label = "# of Votes",
Data = new[] { 12, 19, 3, 5, 2, 3 },
BorderWidth = 1
},
new
{
Label = "# of Votes",
Data = new[] { 12, 19, 3, 5, 2, 3 },
BorderWidth = 1
}
}
},
Options = new
{
Responsive = true,
Scales = new
{
X = new
{
Display = true,
BeginAtZero = true
},
Y = new
{
Display = true,
BeginAtZero = true,
Grace = "10%"
}
},
Plugins = new
{
Legend = new
{
Display = true,
Position = "top"
}
}
}
};
public async Task Rerender()
{
if(_isInitializing)
{
return;
}
await _chart!.Rerender();
}
public async Task Update()
{
if(_isInitializing)
{
return;
}
var data = new
{
Labels = new[] { "faast", "Blue", "Yellow", "Green", "Purple", "Orange" },
Datasets = new[]
{
new
{
Label = "# of Votes",
Data = new[] { 55, 19, 3, 5, 2, 3 },
BorderWidth = 1
},
new
{
Label = "# of Votes",
Data = new[] { 12, 19, 3, 5, 2, 3 },
BorderWidth = 1
}
}
};
await _chart!.Update(data, false);
}
}
Contribution is welcome BUT:
- only to improve basic functionality of the wrapper. Purpose of this wrapper is to be as simple as possible.
- to fix bugs
- to automate overall workflow
How to manually adjust chart.js
- clone official Chart.js repo
- do necessary changes
- install
pnpmfrom here - open powershell as admin
- ⚠️ in case you dont have privileges to run scripts then run:
Set-ExecutionPolicy -ExecutionPolicy Bypass- select option
Afor all
- select option
- ⚠️ in case you dont have privileges to run scripts then run:
- navigate to
Chart.jsfolder - run following scripts
pnpm installpnpm install -g jsonjson -I -f package.json -e "this.version='9.9.9'"pnpm run buildpnpm pack
- then the final minified file is located in
dist/chart.umd.js - rename
chart.umd.jstoChart.js - then replace
wwwroot/Chart.jswith the new one
TODO
- add examples
- automate ChartJS version bump
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
4.3.0.8 Release (2024-06-23)
- Added "beforeWebStart" JS initializer
4.3.0.7 Release (2024-05-31)
- Added "Classes" parameter
4.3.0.6 Release (2024-03-05)
- Added new update method
4.3.0.5 Release (2024-03-04)
- Changed body of 2 methods
- Improved parsing of config object
4.3.0.4 Release (2023-07-20)
- Merged external PR and built custom Chart.js based on v4.3.0
4.3.0.3 Release (2023-07-05)
- Added ClearChartData method
- Added ColorHelper
4.3.0.2 Release (2023-07-04)
- Dependency package version downgrade
4.3.0.1 Release (2023-07-04)
- Fixed Readme
4.3.0.0-preview1 Release (2023-07-04)
- Initial release