Line chart
A line chart joins measurements in order so changes in direction are easy to see. Keep the intervals consistent and name the units.
Compare daily balances
#Compare the balance over the first four days of January and February. January dips on day three, while February rises each day.
components/line-chart/appliance/compare_balances.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class CompareBalances extends StatefulWidget {
const CompareBalances({super.key});
@override
State<CompareBalances> createState() => _CompareBalancesState();
}
class _CompareBalancesState extends State<CompareBalances> {
bool alternate = false;
String get period => alternate ? 'February' : 'January';
List<double> get balances =>
alternate ? const [86, 92, 98, 112] : const [90, 100, 94, 106];
@override
Widget build(BuildContext context) => SingleChildScrollView(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 420),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('$period · daily balance'),
const SizedBox(height: 12),
ApplianceLineChart(
labels: const ['1', '2', '3', '4'],
series: [ApplianceChartSeries('Balance', balances)],
semanticLabel: '$period daily balance',
),
const SizedBox(height: 12),
ApplianceButton(
alternate ? 'Show January' : 'Show February',
onPressed: () => setState(() => alternate = !alternate),
),
],
),
),
);
}
Parameters
ApplianceLineChart API ↗labels- A label for each position along the horizontal axis.
series- The series name and ordered measurements.
semanticLabel- Names the chart and period.
height- Sets the plot height.
valueText- Formats a value in the chart readout.
Shared behaviour
- Keyboard and focus. Tab to the period button and activate it. Where the chart accepts focus, try its arrow keys to inspect a point.
- Screen readers. Read the period and the chart’s description. The value or summary provided by the look changes with the data.
- Direction and type. The surrounding text follows reading direction. Check the plot’s own ordering, labels and legend in RTL and at larger type.