Skip to main content

LCLA Context

An LclaContext is the shared charting environment for a client application. It owns the connection to the renderer, the available datasets, and any charts created from it. Create one context, then create as many charts as your application needs. This lets charts use the same data without copying it for every view.

Every context requires an LclaLicense. Supply a LightningChart JS license key when creating it. Application deployment licenses can also include the application title and company information.

note

Flutter currently uses a different model: create charts directly, with each chart acting as its own context. Consequently, Flutter can only support up to 16 charts at once.

Creating a context​

Create the context in your .razor component after the chart container has rendered.

This example reads the license key from the application's LCJS_LICENSE_KEY configuration setting:

@using LightningChart.LA.Api
@using LightningChart.LA.Blazor
@using Microsoft.JSInterop
@inject IJSRuntime JSRuntime
@inject IConfiguration Configuration

@code {
private LclaContext? _context;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender) return;

var license = new LclaLicense
{
Key = Configuration["LCJS_LICENSE_KEY"]!,
};

_context = new LclaContext(new BlazorTransport(JSRuntime), license);
}
}

Continue to Adding charts to create a chart.

Disposing a context​

Add this directive at the top of your .razor component:

@implements IAsyncDisposable

Add the following method inside the component's existing @code block:

public async ValueTask DisposeAsync()
{
if (_context is not null)
await _context.DisposeAsync();
}

Blazor calls this method when the component is removed. Disposing _context releases the charts it owns.