Flutter
Use LightningChart Flutter on Web, Android, iOS, and macOS.
Tested with Flutter 3.44.
Install
flutter pub add lightning_chart_flutter
Example
The Flutter example on GitHub displays a patient monitoring dashboard with ECG, blood pressure, oxygen saturation, and respiratory rate. Monitor mode shows current measurements, while Review mode shows recording statistics. Its README walks through running it locally.
License key
LightningChart Flutter requires a license key. Get a free trial key or use your commercial key. One way to keep the key out of source code is to provide it with --dart-define:
flutter run -d chrome --dart-define=LCJS_LICENSE_KEY=your-license-key
Read it when constructing the widget:
import 'package:lightning_chart_flutter/lightning_chart_flutter.dart';
const licenseKey = String.fromEnvironment('LCJS_LICENSE_KEY');
const license = LclaLicense(
key: licenseKey,
appTitle: 'My Flutter App',
company: 'My Company',
);
appTitle and company default to trial values. Set both for app deployment licenses.
Creating a chart
Pass license to LightningChart.xy. The widget initializes and owns its chart resources; you do not create a separate context.
The following creates a line series using the "time" and "value" columns of the "signals" dataset. Add the widget to your application's layout:
LightningChart.xy(
license: license,
title: 'Signal chart',
dataSets: const [
DataSetConfig(
id: 'signals',
maxSampleCount: 1_000_000,
columns: [
DataSetColumnConfig(
id: 'time',
dataPattern: DataPattern.progressive,
),
DataSetColumnConfig(id: 'value'),
],
),
],
series: const [
LineSeriesConfig(
id: 'signal',
dataSetId: 'signals',
x: 'time',
y: 'value',
name: 'Signal',
),
],
);
Historical data
Acquire data through the repository, HTTP client, or file workflow your Flutter application normally uses. Pass the resulting typed arrays as initialData when creating the chart.
Here, signalRepository represents your application's data source. The following belongs in an asynchronous data-loading method, rather than directly in a widget's synchronous build method:
final samples = await signalRepository.loadHistoricalSamples();
return LightningChart.xy(
license: license,
title: 'Historical signal',
dataSets: const [
DataSetConfig(
id: 'signals',
maxSampleCount: 1_000_000,
columns: [
DataSetColumnConfig(
id: 'time',
dataPattern: DataPattern.progressive,
),
DataSetColumnConfig(id: 'value'),
],
),
],
series: const [
LineSeriesConfig(
id: 'signal',
dataSetId: 'signals',
x: 'time',
y: 'value',
name: 'Signal',
),
],
initialData: [
SetDataOptions(
dataSetId: 'signals',
columns: {
'time': samples.timestamps,
'value': samples.values,
},
),
],
);
timestamps and values are Float64List instances with equal lengths. Timestamps are in milliseconds.
Use your application's asynchronous loading UI, such as a FutureBuilder, to display the resulting widget.
Real-time data
For incoming data from a device, service, or WebSocket, append each received batch to the dataset.
Store the subscription in your widget's state:
import 'dart:async';
StreamSubscription<dynamic>? _subscription;
Here, signalRepository.liveBatches represents your application's incoming data stream. Each batch supplies timestamps and values as Float64List instances, with timestamps in milliseconds.
The following belongs inside the stateful widget's build method. It creates a chart with a ten-second scrolling window and starts listening after the chart is ready:
return LightningChart.xy(
license: license,
dataSets: const [
DataSetConfig(
id: 'signals',
maxSampleCount: 1_000_000,
columns: [
DataSetColumnConfig(
id: 'time',
dataPattern: DataPattern.progressive,
),
DataSetColumnConfig(id: 'value'),
],
),
],
axes: const [
AxisConfig(
axis: AxisTarget.x,
scrollStrategy: ScrollStrategy.scrolling,
defaultInterval: AxisDefaultIntervalConfig(
length: 10_000,
),
),
],
series: const [
LineSeriesConfig(
id: 'signal',
dataSetId: 'signals',
x: 'time',
y: 'value',
name: 'Signal',
),
],
onChartCreated: (chart) {
_subscription = signalRepository.liveBatches.listen((batch) {
chart.appendData(AppendDataOptions(
dataSetId: 'signals',
columns: {
'time': batch.timestamps,
'value': batch.values,
},
));
});
},
);
Cancel the subscription when the widget is removed:
void dispose() {
_subscription?.cancel();
super.dispose();
}
The chart widget releases its chart resources automatically.
On Android, add the INTERNET permission. If loopback traffic is blocked, allow cleartext traffic to 127.0.0.1 through your application's network security configuration.
More features
LightningChart Flutter supports multiple axes, configurable series, historical data, and real-time streaming. For complete feature coverage, see Features.
Feedback and contributions
LightningChart Flutter is open source on GitHub. You can contribute an improvement or open an issue, or contact the LightningChart team through lightningchart.com or at [email protected].