PieChart class

A chart type which plots the values in the form of a pie with different slices representing different values. It takes the @required values parameter which provides the data to plot the graph.

The other parameters are optional which define different behaviors for the chart like:

labels which will be shown in the graph, if not provided, will default to the value of data points. If provided, it's length should be same as that of values

size which defines the canvas area defaults to Size.infinite and is constrained by the parent widget.

sliceFillColors defines the background color of each slice of the graph, if not provided, random colors will be generated.

maxHeight and maxWidth defines the maximum width and height of the chart when no parent constraints are applied, otherwise ignored.

labelColor defines the color of the chart values, defaults to Colors.black.

legendTextColor defines the color of the chart legend text, defaults to Colors.black.

legendPosition defines the position of the chart legend in the layout. It can either be LegendPosition.Left, LegendPosition.Top, LegendPosition.Right or LegendPosition.Bottom. The default position is LegendPosition.Right.

legendIconSize defines the size of the legend icons. The default size value is 10.0

legendTextSize defines the the text size of the legend labels. The default text size is 16.0

legendItemPadding defines the padding around and in between the legend row items. The default padding is 8.0

legendIconShape defines the shape of the legend icons. It can either be LegendIconShape.Circle or LegendIconShape.Square. The default shape is LegendIconShape.Square.

textScaleFactor defines the factor by which the label's textSize increases with respect to the average of width and height of the enclosing parent widget, if not provided defaults to 0.04

animate defines the animation toggle, if true, the chart will animate, else not. Defaults to true.

animationDuration defines the duration (in milliseconds) of the animation for the graph. If not provided, defaults to 1500 milliseconds.

curve defines the animation's progress in a non-linear fashion.

separateFocusedValue defines whether we want to highlight focused value (of type: SeparatedValue.Max or SeparatedValue.Min) as a slice separated from the chart. By default, it is set to false.

separatedValueType defines which value slice to show as separated. It can be either SeparatedValue.Max or SeparatedValue.Min. The default value is SeparatedValue.Max

startAngle defines the start angle (in degrees) of the chart's radial position. The default value is 180.

showLegend defines whether to show the chart legend or not. By default, it is set to true.

Inheritance

Constructors

PieChart({Key? key, required List<double> values, List<String>? labels, Size size = Size.infinite, List<Color>? sliceFillColors, double maxWidth = 200, double maxHeight = 200, Color labelColor = Colors.black, Color legendTextColor = Colors.black, LegendPosition legendPosition = LegendPosition.Right, double legendIconSize = 10.0, double legendTextSize = 16.0, EdgeInsetsGeometry legendItemPadding = const EdgeInsets.all(8.0), LegendIconShape legendIconShape = LegendIconShape.Square, double textScaleFactor = 0.04, bool animate = true, Duration animationDuration = const Duration(milliseconds: 1500), Curve curve = Curves.easeIn, bool separateFocusedValue = false, SeparatedValue separatedValueType = SeparatedValue.Max, double startAngle = 180, bool showLegend = true})
It plots the values as slices of pie
const

Properties

animate bool
It is the animation toggle
final
animationDuration Duration
Defines the duration of the animation for the graph.
final
curve Curve
It defines the animation style
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
labelColor Color
Defines the color of the chart labels
final
labels List<String>?
Provides naming for the data points
final
legendIconShape LegendIconShape
Defines the shape of the legend icons
final
legendIconSize double
Defines the size of the legend icons
final
legendItemPadding EdgeInsetsGeometry
The padding around and in between the legend row items
final
legendPosition LegendPosition
The position of the chart legend in the layout
final
legendTextColor Color
Defines the color of the chart legend text
final
legendTextSize double
Defines the the text size of the legend labels
final
maxHeight double
Defines the maximum height of the chart
final
maxWidth double
Defines the maximum width of the chart
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
separatedValueType SeparatedValue
Defines which value to show as separated slice
final
separateFocusedValue bool
Highlights the max or min focused value as separated slice from chart.
final
showLegend bool
Whether to show chart legend
final
size Size
Defines the size of the canvas
final
sliceFillColors List<Color>?
Defines the background color of each slice of the chart
final
startAngle double
Defines the start angle (in degrees) of the chart's radial position
final
textScaleFactor double
Percent factor of text size wrt to Height and Width
final
values List<double>
Data points of the graph
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → _PieChartState
Creates the mutable state for this widget at a given location in the tree.
override
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