any_sparklines 2.2.4
any_sparklines: ^2.2.4 copied to clipboard
Feature-rich and highly optimized sparklines for Flutter
Sparklines #
Feature-rich, highly optimized sparklines for Flutter. Line, bar, pie, and between-line charts with shared layouts, animation, and flexible styling.

Core concepts #
Layouts #
- AbsoluteLayout — Data coordinates map 1:1 to pixels; origin bottom-left, Y up.
- RelativeLayout — Data is scaled to explicit bounds. Use
RelativeLayout.normalized()(0–1),RelativeLayout.signed()(-1–1), orRelativeLayout.full()(auto from data). SetminX/maxX/minY/maxYtodouble.infinityordouble.negativeInfinityto derive from chart data. Identical layout instances are resolved once and shared across all charts using them. - RelativeDimension — For
RelativeLayout, userelativeTo: RelativeDimension.widthorRelativeDimension.heightso lengths (e.g. stroke width) scale with chart size;noneuses absolute values.
Rotation, flip, and origin #
- ChartRotation —
d0,d90,d180,d270(clockwise). Ford90/d270, logical width/height are swapped so the chart fills the widget. - ChartFlip —
none,vertically,horizontally,both. Flip charts around axes; applied after rotation. - origin —
Offsetapplied before rotation; use to position charts.
Crop and visibility #
- crop — When
true, rendering is clipped to chart bounds. Chart-levelcropoverrides the widget default. - visible — Per-chart; when
false, the chart is skipped.
DataPoint #
- x — X coordinate.
- y — Base Y (e.g. stacked base).
- dy — Delta from base; fy = y + dy is the value used for drawing.
- data — Extensible
Map<Type, IDataPointData?>for per-point metadata. Keys are type tokens; values implementIDataPointData(supportslerpTofor animation). Usepoint.of<M>()for type-safe access.
Common data entries (via extension getters or of<M>()):
- style —
IDataPointStyle?(e.g.CircleDataPointStyle) for point markers. - thickness —
IThicknessOverride?(size, color, gradient, align) to override chart thickness for this point. - pieOffset —
IPieOffset?for pie slice offset. - DataPointMeta —
id,key,labelfor tooltips or identification.
Thickness (global and per-point) #
- ThicknessData —
size,color, optionalgradient(overrides color),align:ThicknessData.alignInside(-1),alignCenter(0),alignOutside(1). - ThicknessOverride on
DataPoint— Same fields; overrides chart thickness for that point.
Border and border radius #
- IChartBorder —
border(ThicknessData?),borderRadius(double?). Used by BarData and PieData.
Area fill (line charts) #
- areaColor / areaGradient — Fill below the line (from line down to base Y). Gradient takes precedence over color.
- areaFillType — Optional
PathFillTypefor the fill.
Line charts #
LineData — line, thickness, areaColor/areaGradient, areaFillType, lineType, pointStyle.
Line types #
- LinearLineData — Straight segments; optional
isStrokeCapRound,isStrokeJoinRound. - SteppedLineData — Step at fraction between points:
stepJumpAt0→prev, 1→next; constructors.start(),.middle(),.end(). - CurvedLineData — Smooth curve;
smoothness0.0–1.0 (default 0.35).
Between-line charts #
BetweenLineData — Fills the area between two lines. from, to (both LineData), areaColor, areaGradient, areaFillType. Uses same layout; both lines share the same coordinate system.
Bar charts #
BarData — bars (List<DataPoint>; fy = top, y = base), thickness, border, borderRadius, pointStyle. Bars are drawn from y to fy; use DataPointPipeline for stacking.
Pie charts #
PieData — Each DataPoint is one arc: x = radius, y = start angle, dy = sweep (end = y + dy). Angles in radians. thickness, padAngle (gap between slices), pieOffset, border, borderRadius, pointStyle. Bounds are computed from slice geometry.
DataPoint pipeline #
DataPointPipeline — Build transformed lists for stacking/normalization; reuse one pipeline for multiple series so shared state (e.g. stacking) is consistent.
- stack({ spacing }) — Stack points by x; each point’s
ybecomes the running sum at that x,dystays the value. Optionalspacingadds gap between stacked segments. - normalize({ total, threshold?, spacing?, trailingSpacing?, thresholdPoint? }) — Scale
dyso sum ofabs(dy)equalstotal(default 1.0).thresholdrepeatedly drops smallest segment until none below threshold;thresholdPointreceives accumulated dy of removed points.spacingreserves gap between segments;trailingSpacingadds one more spacing (useful for full pies). - normalize2pi({ total, threshold?, spacing?, spacingDeg?, trailingSpacing?, thresholdPoint? }) — Same as
normalizewith defaulttotal2π for angles.spacingDegis spacing in degrees (converted to radians);trailingSpacingdefaults to true whentotal >= 2ortotal <= -2. - rescale({ currentMin?, currentMax?, targetMin, targetMax }) — Linearly rescale intervals
[DataPoint.y..DataPoint.fy]from[currentMin..currentMax]to[targetMin..targetMax](default 0–1). Bothyandfyare transformed;dyis recalculated asfy - y. IfcurrentMinorcurrentMaxare not finite, they are computed from input interval bounds. - sort({ x?, y?, fy? }) — Sort input by x, y, and/or fy. Each:
true= ascending,false= descending. If all null, sorts by x ascending. - aggregate({ function, window? }) — Aggregate
dyover a window ending at each point.function:DataAggregation.sum,.avg,.min,.max,.median,.std(defaultsum).window: null = cumulative from start, N = last N elements. Updatesdyandfyper point.
IThresholdPoints / ThresholdPoints — When normalize removes below-threshold points and uses thresholdPoint, the aggregate point’s data contains ThresholdPoints(removed) so you can access the original points via point.of<IThresholdPoints>()?.thresholdPoints.
final pipeline = DataPointPipeline().stack().normalize(total: 1.0);
final seriesA = pipeline.build(rawPointsA);
final seriesB = pipeline.build(rawPointsB);
Widget options #
SparklinesChart
- charts — List of
ISparklinesData(e.g.LineData,BarData,PieData,BetweenLineData). - layout — Default
IChartLayout(e.g.AbsoluteLayout(),RelativeLayout.full()). - crop — Default clip-to-bounds.
- width / height — Fixed size; one can be null and filled by layout.
- aspectRatio — Used when both width and height are null.
- animate — Enable data-driven animation (default
true). - animationDuration — Default 300 ms.
- animationCurve — Default
Curves.easeInOut.
Charts implement ILerpTo for smooth transitions when data changes.
Extending #
- IDataPointStyle + IDataPointRenderer — Custom point markers.
- IChartRenderer — Custom chart types.
- ILineTypeData + ILineTypeRenderer — Custom line path and stroke.
- IChartLayout — Custom coordinate systems; implement
resolve(),transform(),transformScalar().
