Skip to main content

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.

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 set Title = "" to hide it.
  • LegendVisible — Show or hide the chart legend, including any LUT color scales. The legend is visible by default; set LegendVisible = false to hide it.
  • AnimationsEnabled — Enable or disable chart animations. Animations are enabled by default; set AnimationsEnabled = false to 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.

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:

_chart.Update(new 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.

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.