Sparkline
A sparkline gives a compact impression of change beside a value or a heading. Use a larger chart when readers need axes or exact comparisons.
Read a five-day trend
#Compare two weeks of requests. The first ends at eight requests and the second ends at four. Read the Monday and Friday counts alongside the small line.
components/sparkline/appliance/read_daily_trend.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class ReadDailyTrend extends StatefulWidget {
const ReadDailyTrend({super.key});
@override
State<ReadDailyTrend> createState() => _ReadDailyTrendState();
}
class _ReadDailyTrendState extends State<ReadDailyTrend> {
bool alternate = false;
String get period => alternate ? 'Week 2' : 'Week 1';
List<double> get requests =>
alternate ? const [9, 8, 6, 7, 4] : const [3, 5, 4, 6, 8];
@override
Widget build(BuildContext context) => SingleChildScrollView(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 420),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'$period · ${requests.first.toInt()} requests on Monday, ${requests.last.toInt()} on Friday',
),
const SizedBox(height: 12),
SizedBox(
width: 106,
child: ApplianceSparkline(
values: requests,
semanticLabel:
'$period daily requests: ${requests.map((v) => v.round()).join(', ')}',
),
),
const SizedBox(height: 12),
ApplianceButton(
alternate ? 'Show Week 1' : 'Show Week 2',
onPressed: () => setState(() => alternate = !alternate),
),
],
),
),
);
}
Parameters
ApplianceSparkline API ↗values- Daily counts in chronological order.
semanticLabel- Names the series and period.
width- Sets the width of the small plot.
height- Sets the height of the small plot.
Shared behaviour
- Keyboard and focus. Tab to the week button and activate it. A sparkline may be a single reading rather than a series of focus stops.
- Screen readers. The adjacent text names the week and gives its first and last counts. Compare it with the description the look gives its sparkline.
- Direction and type. The small plot sits beside the week’s reading. Check the direction of the line and the larger text separately.