Drafter
π A powerful, flexible charting library for Flutter β a native Dart port of Drafter for Compose and DrafterCharts for SwiftUI.
Features
- π 27 chart types out of the box:
- Bars β Bar, Grouped Bar, Stacked Bar, Histogram, Waterfall
- Lines β Line, Grouped Line, Stacked Line, Step Line, Area
- Distribution β Scatter, Bubble, Box Plot, Candlestick
- Part-to-whole β Pie, Donut, Funnel, Treemap, Polar Area, Sunburst
- Specialized β Radar, Gantt, Gauge, Bullet, Sankey, Stream Graph, Contribution Heatmap
- π¨ Highly customizable appearance with a shared
DrafterThemeColors (light/dark, custom palettes)
- β¨ Smooth, premium rendering β Catmull-Rom curves, soft gradient fills, rounded shapes
- π¬ Built-in left-to-right reveal animation with a one-line
replay hook
- π Pure Flutter
CustomPaint/Canvas, zero dependencies beyond the SDK
- π± Immutable value-type data models and an
InheritedWidget-based theme
- βΏοΈ Semantics built in β every chart announces its kind and a data summary, so a
Canvas is never silently invisible to screen readers
- π§© One consistent, type-safe API β every chart takes its bound elements directly (
points:, series:, bars:, slices:, nodes:β¦), so a label can't desync from its value and there's no data: wrapper to learn
Installation
Add Drafter to your pubspec.yaml:
dependencies:
drafter: ^0.2.0
Or from the command line:
And import it:
import 'package:drafter/drafter.dart';
Anatomy of a chart
Every chart is a Flutter Widget that takes an immutable data model. Two optional
knobs are shared by all charts:
| Parameter |
Default |
Meaning |
animate |
true |
Play the left-to-right reveal on first build. Pass false to draw fully revealed. |
replay |
0 |
Change this value (e.g. from a button) to replay the entrance animation. |
AreaChart(points: areaPoints) // animates on build
AreaChart(points: areaPoints, animate: false) // static
AreaChart(points: areaPoints, replay: replayKey) // bump replayKey to re-run
Size charts like any Flutter widget (SizedBox, AspectRatio, Expandedβ¦), and
set the palette / light-dark with a DrafterTheme ancestor.
For the simplest single-series charts there are values-first convenience
constructors, so trivial cases can skip building labeled elements:
LineChart.values(values: [40, 65, 50, 80, 70, 95])
AreaChart.values(values: [12, 18, 9, 24, 20, 30], color: DrafterColors.teal)
SimpleBarChart.values(values: [24, 38, 30, 46])
StepLineChart.values(values: [10, 25, 18, 32])
ScatterPlot.values(values: [(1, 2), (3, 5), (4, 3)]) // raw (x, y) pairs
The full point/series form (points:, series:, bars:) is the primary API for
labels, multi-series, and per-element colors.
Table of Contents
- Bar Charts β Simple Β· Grouped Β· Stacked
- Line Charts β Simple Β· Grouped Β· Stacked
- Histogram Chart
- Waterfall Chart
- Area Chart
- Step Line Chart
- Pie & Donut Chart
- Scatter Plot Chart
- Bubble Chart
- Candlestick Chart
- Box Plot Chart
- Radar Chart
- Gauge Chart
- Bullet Chart
- Funnel Chart
- Treemap Chart
- Polar Area Chart
- Sunburst Chart
- Sankey Chart
- Stream Graph Chart
- Gantt Chart
- Heatmap Chart
Every snippet below renders a single chart. Wrap it in a SizedBox (or any
sizing widget) to give it bounds, as shown in the first example.
Bar Charts
Simple Bar Chart
SizedBox(
height: 300,
child: SimpleBarChart(
bars: const [BarItem('Q1', 24), BarItem('Q2', 38), BarItem('Q3', 30), BarItem('Q4', 46)],
),
)
Grouped Bar Chart
GroupedBarChart(
series: [
ChartSeries(name: '2023', color: DrafterColors.blue, values: [20, 34, 26, 40]),
ChartSeries(name: '2024', color: DrafterColors.teal, values: [28, 30, 38, 44]),
],
categories: const ['Q1', 'Q2', 'Q3', 'Q4'],
)
Stacked Bar Chart
StackedBarChart(
series: [
ChartSeries(color: DrafterColors.blue, values: [12, 16, 14, 20]),
ChartSeries(color: DrafterColors.teal, values: [8, 10, 12, 14]),
ChartSeries(color: DrafterColors.violet, values: [6, 8, 10, 9]),
],
categories: const ['Q1', 'Q2', 'Q3', 'Q4'],
)
Line Charts
Simple Line Chart
LineChart(
points: const [ChartPoint('Jan', 40), ChartPoint('Feb', 65), ChartPoint('Mar', 50), ChartPoint('Apr', 80)],
color: DrafterColors.blue,
)
Grouped Line Chart
GroupedLineChart(
series: [
ChartSeries(name: 'A', color: DrafterColors.blue, values: [30, 45, 40, 70]),
ChartSeries(name: 'B', color: DrafterColors.teal, values: [20, 35, 50, 45]),
],
categories: const ['Jan', 'Feb', 'Mar', 'Apr'],
)
Stacked Line Chart
StackedLineChart(
series: [
ChartSeries(color: DrafterColors.violet, values: [10, 14, 12, 20]),
ChartSeries(color: DrafterColors.green, values: [8, 10, 14, 12]),
],
categories: const ['Jan', 'Feb', 'Mar', 'Apr'],
)
Histogram Chart
Histogram(
values: const [2, 3, 3, 4, 5, 5, 6, 7, 8, 9, 10, 12, 13, 15],
binCount: 5,
)
Waterfall Chart
Each WaterfallStep is an incremental change applied to initialValue; the
number of bars is driven by steps (one step per delta), so the counts always
line up.
WaterfallChart(
steps: const [WaterfallStep('Revenue', 50), WaterfallStep('Cost', -20), WaterfallStep('Profit', 30)],
initialValue: 100,
)
Opt into a leading Start bar (the initial value) and a trailing Total
bar (the final running total) β the classic Start β¦ Total waterfall:
WaterfallChart(
steps: const [WaterfallStep('Sales', 60), WaterfallStep('Costs', -25), WaterfallStep('Tax', -10)],
initialValue: 50,
startLabel: 'Start', // draws a leading bar at the initial value
totalLabel: 'Net', // draws a trailing bar at the final running total
)
Counts don't have to be perfect: every chart drives its element count from the
value arrays, and mismatched categories/colors are handled gracefully
(missing entries fall back, extras are ignored) β no ghost columns or crashes.
Area Chart
AreaChart(
points: const [
ChartPoint('Jan', 12), ChartPoint('Feb', 28), ChartPoint('Mar', 18),
ChartPoint('Apr', 34), ChartPoint('May', 24), ChartPoint('Jun', 40),
],
color: DrafterColors.blue,
)
Step Line Chart
StepLineChart(
points: const [
ChartPoint('Jan', 10), ChartPoint('Feb', 25),
ChartPoint('Mar', 18), ChartPoint('Apr', 32),
],
)
Pie & Donut Chart
final slices = [
PieSlice(value: 40, color: DrafterColors.blue, label: 'Blue'),
PieSlice(value: 30, color: DrafterColors.teal, label: 'Teal'),
PieSlice(value: 20, color: DrafterColors.violet, label: 'Violet'),
PieSlice(value: 10, color: DrafterColors.amber, label: 'Amber'),
];
PieChart(slices: slices);
DonutChart(slices: slices);
Scatter Plot Chart
ScatterPlot(
points: [
const ScatterPoint(x: 1, y: 2),
const ScatterPoint(x: 2, y: 5),
ScatterPoint(x: 3, y: 3, color: DrafterColors.coral),
],
)
Bubble Chart
BubbleChart(
series: [
[ BubbleData(x: 10, y: 26, size: 30, color: DrafterColors.blue),
BubbleData(x: 26, y: 30, size: 60, color: DrafterColors.blue) ],
[ BubbleData(x: 14, y: 15, size: 30, color: DrafterColors.teal),
BubbleData(x: 22, y: 36, size: 45, color: DrafterColors.teal) ],
],
)
Candlestick Chart