Sparkline class

A widget that draws a sparkline chart.

Represents the given data in a sparkline chart that spans the available space.

By default only the sparkline is drawn, with its looks defined by the lineWidth, lineColor, and lineGradient properties.

The y-scale of the sparkline will be determined by using the data's minimum and maximum value, unless overridden with min and/or max.

The corners between two segments of the sparkline can be made sharper by setting sharpCorners to true.

Conversely, to smooth out the curve drawn even more, set useCubicSmoothing to true. The degree to which the cubic smoothing is applied can be changed using cubicSmoothingFactor. A good range for cubicSmoothingFactor is usually between 0.1 and 0.3.

The area above or below the sparkline can be filled with the provided fillColor or fillGradient by setting the desired fillMode.

pointsMode controls how individual points are drawn over the sparkline at the provided data point. Their appearance is determined by the pointSize and pointColor properties.

By default, the sparkline is sized to fit its container. If the sparkline is in an unbounded space, it will size itself according to the given fallbackWidth and fallbackHeight.

Inheritance

Constructors

Sparkline({Key? key, required List<double> data, double lineWidth = 1.0, Color lineColor = Colors.lightBlue, Gradient? lineGradient, PointsMode pointsMode = PointsMode.none, int? pointIndex, double pointSize = 4.0, Color pointColor = const Color(0xFF0277BD), bool sharpCorners = false, bool useCubicSmoothing = false, double cubicSmoothingFactor = 0.15, FillMode fillMode = FillMode.none, Color fillColor = const Color(0xFF81D4FA), Gradient? fillGradient, double fallbackHeight = 100.0, double fallbackWidth = 300.0, bool enableGridLines = false, String gridLinelabel(double gridLineValue)?, Color gridLineColor = Colors.grey, int gridLineAmount = 5, double gridLineWidth = 0.5, Color gridLineLabelColor = Colors.grey, bool enableThreshold = false, double thresholdSize = 0.3, double? max, double? min, String gridLinelabelPrefix = "", int gridLineLabelPrecision = 3, bool averageLine = false, bool averageLabel = true, bool maxLine = false, bool maxLabel = true, List? kLine, Color? backgroundColor})
Creates a widget that represents provided data in a Sparkline chart.

Properties

averageLabel bool
average Label
final
averageLine bool
average Line
final
backgroundColor Color?
backgroudColor
final
cubicSmoothingFactor double
How aggressively the sparkline should apply cubic beziers to smooth the curves. A good value is usually between 0.1 and 0.3.
final
data List<double>
List of values to be represented by the sparkline.
final
enableGridLines bool
Enable or disable grid lines
final
enableThreshold bool
Define if graph should have threshold
final
fallbackHeight double
The height to use when the sparkline is in a situation with an unbounded height.
final
fallbackWidth double
The width to use when the sparkline is in a situation with an unbounded width.
final
fillColor Color
The fill color used in the chart, as determined by fillMode.
final
fillGradient Gradient?
A gradient to use when filling the chart, as determined by fillMode.
final
fillMode FillMode
Determines the area that should be filled with fillColor.
final
gridLineAmount int
Number of grid lines
final
gridLineColor Color
Color of grid lines and label text
final
gridLinelabel → (String Function(double gridLineValue)?)
Grid line labels callback Takes the grid line Value and returns a string
final
gridLineLabelColor Color
final
gridLineLabelPrecision int
Digit precision of grid line labels
final
gridLinelabelPrefix String
Symbol prefix for grid line labels
final
gridLineWidth double
Width of grid lines
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
kLine List?
kLine= 'max', 'min', 'first', 'last'
final
lineColor Color
The color of the sparkline.
final
lineGradient Gradient?
A gradient to use when coloring the sparkline.
final
lineWidth double
The width of the sparkline.
final
max double?
The maximum value for the rendering box. Will default to the largest value in data.
final
maxLabel bool
max Label
final
maxLine bool
max Line
final
min double?
The minimum value for the rendering box. Will default to the largest value in data.
final
pointColor Color
The color used when drawing individual data points over the sparkline.
final
pointIndex int?
The index to draw a point at when pointsMode is atIndex.
final
pointSize double
The size to use when drawing individual data points over the sparkline.
final
pointsMode PointsMode
Determines how individual data points should be drawn over the sparkline.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sharpCorners bool
Determines if the sparkline path should have sharp corners where two segments intersect.
final
thresholdSize double
size of default threshold (in Percent) 0.0 ~ 1.0
final
useCubicSmoothing bool
Determines if the sparkline path should use cubic beziers to smooth the curve when drawing. Read more about the algorithm used, here:
final

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited