Bar chart
A bar chart compares separate amounts against the same baseline. Give each bar a category readers can identify without colour.
Compare monthly orders
#Compare orders in the first and second quarters. The second month has the most orders in the first quarter and the fewest in the second.
components/bar-chart/appliance/compare_quarters.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class CompareQuarters extends StatefulWidget {
const CompareQuarters({super.key});
@override
State<CompareQuarters> createState() => _CompareQuartersState();
}
class _CompareQuartersState extends State<CompareQuarters> {
bool alternate = false;
String get period => alternate ? 'Q2' : 'Q1';
List<double> get orders =>
alternate ? const [18, 10, 24] : const [12, 20, 16];
List<String> get months =>
alternate ? const ['Apr', 'May', 'Jun'] : const ['Jan', 'Feb', 'Mar'];
@override
Widget build(BuildContext context) => SingleChildScrollView(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 420),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('$period · monthly orders'),
const SizedBox(height: 12),
ApplianceBarChart(
labels: months,
series: [ApplianceChartSeries('Orders', orders)],
semanticLabel: '$period monthly orders',
),
const SizedBox(height: 12),
ApplianceButton(
alternate ? 'Show Q1' : 'Show Q2',
onPressed: () => setState(() => alternate = !alternate),
),
],
),
),
);
}
Parameters
ApplianceBarChart 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.