Adding charts
LightningChart LA creates interactive XY charts with panning and zooming enabled by default. Use your application's normal layout components to position and size each chart.
Creating a chart
Set the chart title, legend visibility, and animation settings when creating a chart. You can also supply datasets, axes, and series in the initial configuration. See Data management, Adding series, and Configuring axes for complete configuration examples.
The examples throughout the Features guides build on the chart created here.
- Blazor
- MAUI
- Uno
- Flutter
Render a chart container in your component:
<div id="signal-chart" style="height: 480px"></div>
The following continues the example from Creating a context. It creates a chart after the container has rendered and the context has been initialized:
private LclaChart? _chart;
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);
_chart = await _context.CreateChartAsync(new XYChartConfig
{
ContainerId = "signal-chart",
Title = "Signal chart",
});
}
Set these properties in XYChartConfig:
ContainerId— The ID of the existing HTML element containing the chart. Size and position that element using your application's layout. The container cannot be changed after chart creation.Title— The title displayed above the plotting area. Omit it to use the default title, or setTitle = ""to hide it.LegendVisible— Show or hide the chart legend, including any LUT color scales. The legend is visible by default; setLegendVisible = falseto hide it.AnimationsEnabled— Enable or disable chart animations. Animations are enabled by default; setAnimationsEnabled = falseto disable them. This setting cannot be changed after chart creation.DataSets— Create datasets containing named data columns. See Data management.Axes— Configure the default axes and create additional axes. Omit the list to use the normal default X and Y axes. See Configuring axes.Series— Create the series that display your data. See Adding series.
The following continues the page from Creating a context.
Add a chart field beside _context:
private LclaChart? _chart;
Replace the existing Navigated event subscription inside the constructor with this version. It creates the chart after navigation succeeds and the context has been initialized:
_webView.Navigated += async (_, args) =>
{
if (args.Result != WebNavigationResult.Success ||
_transport is null ||
_context is not null)
{
return;
}
var licenseKey = Environment.GetEnvironmentVariable("LCJS_LICENSE_KEY")
?? throw new InvalidOperationException("LCJS_LICENSE_KEY is not configured.");
var license = new LclaLicense
{
Key = licenseKey,
};
_context = new LclaContext(_transport, license);
_chart = await _context.CreateChartAsync(new XYChartConfig
{
Title = "Signal chart",
});
};
Keep the existing Loaded event subscription. Size and position the chart through the WebView's native layout.
Set these properties in XYChartConfig:
Title— The title displayed above the plotting area. Omit it to use the default title, or setTitle = ""to hide it.LegendVisible— Show or hide the chart legend, including any LUT color scales. The legend is visible by default; setLegendVisible = falseto hide it.AnimationsEnabled— Enable or disable chart animations. Animations are enabled by default; setAnimationsEnabled = falseto disable them. This setting cannot be changed after chart creation.DataSets— Create datasets containing named data columns. See Data management.Axes— Configure the default axes and create additional axes. Omit the list to use the normal default X and Y axes. See Configuring axes.Series— Create the series that display your data. See Adding series.
The following continues the page from Creating a context.
Add a chart field beside _context:
private LclaChart? _chart;
Replace the existing NavigationCompleted event subscription inside the constructor with this version. It creates the chart after navigation succeeds and the context has been initialized:
_webView.NavigationCompleted += async (_, args) =>
{
if (!args.IsSuccess ||
_transport is null ||
_context is not null)
{
return;
}
var licenseKey = Environment.GetEnvironmentVariable("LCJS_LICENSE_KEY")
?? throw new InvalidOperationException("LCJS_LICENSE_KEY is not configured.");
var license = new LclaLicense
{
Key = licenseKey,
};
_context = new LclaContext(_transport, license);
_chart = await _context.CreateChartAsync(new XYChartConfig
{
Title = "Signal chart",
});
};
Keep the existing Loaded event subscription. Size and position the chart through the WebView's native layout.
Set these properties in XYChartConfig:
Title— The title displayed above the plotting area. Omit it to use the default title, or setTitle = ""to hide it.LegendVisible— Show or hide the chart legend, including any LUT color scales. The legend is visible by default; setLegendVisible = falseto hide it.AnimationsEnabled— Enable or disable chart animations. Animations are enabled by default; setAnimationsEnabled = falseto disable them. This setting cannot be changed after chart creation.DataSets— Create datasets containing named data columns. See Data management.Axes— Configure the default axes and create additional axes. Omit the list to use the normal default X and Y axes. See Configuring axes.Series— Create the series that display your data. See Adding series.
Continue with the license configuration from Creating a context.
Add the Flutter widgets import alongside the existing client-library import:
import 'package:flutter/widgets.dart';
Below the license declaration, add this widget:
class SignalChart extends StatefulWidget {
const SignalChart({super.key});
State<SignalChart> createState() => _SignalChartState();
}
class _SignalChartState extends State<SignalChart> {
LightningChartController? _chart;
Widget build(BuildContext context) {
return SizedBox(
height: 480,
child: LightningChart.xy(
license: license,
title: 'Signal chart',
onChartCreated: (chart) {
_chart = chart;
},
),
);
}
}
Place const SignalChart() in your application's widget tree. onChartCreated receives the controller when the chart is ready.
The example stores it in _chart so other methods in _SignalChartState can update the chart or supply data.
Set these parameters in LightningChart.xy:
title— The title displayed above the plotting area. Omit it to use the default title, or settitle: ''to hide it.legendVisible— Show or hide the chart legend, including any LUT color scales. The legend is visible by default; setlegendVisible: falseto hide it.animationsEnabled— Enable or disable chart animations. Animations are enabled by default; setanimationsEnabled: falseto disable them. This setting cannot be changed after chart creation.dataSets— Create datasets containing named data columns. See Data management.axes— Configure the default axes and create additional axes. Omit the list to use the normal default X and Y axes. See Configuring axes.series— Create the visualizations that display your data. See Adding series.initialData— Supply dataset data to load when the chart is ready. See Data management.
Updating a chart
Use an update configuration to change the chart title, legend visibility, or configure datasets, axes, and series after creation. Omitted objects and properties remain unchanged. The chart's container and animation setting cannot be changed after creation.
The following changes the chart title and hides the legend:
- Blazor
- MAUI
- Uno
- Flutter
_chart.Update(new UpdateXYChartConfig
{
Title = "Updated signal chart",
LegendVisible = false,
});
_chart.Update(new UpdateXYChartConfig
{
Title = "Updated signal chart",
LegendVisible = false,
});
_chart.Update(new UpdateXYChartConfig
{
Title = "Updated signal chart",
LegendVisible = false,
});
Inside a method of _SignalChartState, obtain the stored controller and check that the chart is ready:
final chart = _chart;
if (chart == null) return;
chart.update(
const UpdateXYChartConfig(
title: 'Updated signal chart',
legendVisible: false,
),
);
See the corresponding feature pages for supported properties and removal rules.
Removing a chart
Release the chart when its view is no longer needed.
- Blazor
- MAUI
- Uno
- Flutter
if (_chart is not null)
await _chart.DisposeAsync();
Call this from your component's cleanup code.
Removing a chart leaves other charts and shared datasets in the same context available. Disposing a context releases all charts it owns.
To remove an individual chart, use the following inside an asynchronous page method:
if (_chart is not null)
{
await _chart.DisposeAsync();
_chart = null;
}
The context cleanup shown on the Context page releases all remaining charts when the page unloads.
Removing a chart leaves other charts and shared datasets in the same context available. Disposing a context releases all charts it owns.
To remove an individual chart, use the following inside an asynchronous page method:
if (_chart is not null)
{
await _chart.DisposeAsync();
_chart = null;
}
The context cleanup shown on the Context page releases all remaining charts when the page unloads.
Removing a chart leaves other charts and shared datasets in the same context available. Disposing a context releases all charts it owns.
Remove SignalChart from the widget tree to release its chart resources.
If you add application-owned data subscriptions or timers to _SignalChartState, cancel them in its dispose method.