NRTDP / SciChartBlazor

A Blazor wrapper for SciChart JS
MIT License
10 stars 5 forks source link

SciChartBlazor

A Blazor wrapper for SciChart JS

Version Package Description
NuGet Package SciChartBlazor .NET 6

Licensing and Trials SciChart no longer requires a license or a trial for community use. You can find details here:

Please Contribute!

This is an open source project that welcomes contributions/suggestions/bug reports from those who use it. If you have any ideas on how to improve the library, please post an issue here on GitHub.

Using SciChartBlazor

First either install the Nuget Package, or pull down the repository and reference the SciChartBlazor project directly.

For Wasm & Server side you need to register the ScichartBlazor Service (and add a license if you need one) in Project.cs, using the following code:

builder.Services.AddSciChart(options =>
{
    options.RuntimeLicenseKey = "LICENSE_HERE"; // if you're using the community license you can leave this bit out
});

Then add a reference to the sciChartBlazorJson.js file in either index.html (for Wasm) or _Layout.cshtml (Server side):

<script async src="https://github.com/NRTDP/SciChartBlazor/raw/main/_content/SciChartBlazor/SciChart/sciChartBlazorJson.js"></script>

Adding a chart to a razor page

Start by adding a div container for the chart:

<div id="@Id" @ref="_chart" style="height:600px" />

id and ref are required and can be set up in the code{} or code-behind. The chart builder class should be Initialized inside OnAfterRenderAsync:

        private string Id { get; set; } = "C" + Guid.NewGuid().ToString();

        private protected ElementReference _chart;

        SciChartBuilder _chartBuilder = default!;

        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            if (firstRender)
            {
                //Create the chart
                _chartBuilder = new SciChartBuilder(_chart, JSRuntime, sciChartBlazorService);
                await _chartBuilder.CreateChart();
            }
            await base.OnAfterRenderAsync(firstRender);
        }

After initialization you can start building your chart. i.e.: