PieChart2D class
A pie chart — or a donut chart if innerRadiusRatio > 0.
PieChart2D(
title: 'Browser Share',
slices: [
PieSlice(label: 'Chrome', value: 64, color: Colors.blue),
PieSlice(label: 'Safari', value: 19, color: Colors.orange),
PieSlice(label: 'Other', value: 17, color: Colors.grey),
],
innerRadiusRatio: 0.6, // set 0 for a solid pie
onSliceTap: (slice) => print(slice?.label),
)
Pinch (or scroll on desktop) to zoom in on the pie; drag to pan while zoomed. A reset button appears while zoomed and restores the original view.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- PieChart2D
Constructors
-
PieChart2D({Key? key, required List<
PieSlice> slices, double innerRadiusRatio = 0, String? title, String? subtitle, String emptyStateMessage = 'No data to display', bool showLegend = true, bool showPercentageLabels = true, String valueFormatter(double value)?, bool enableAnimation = true, Duration animationDuration = const Duration(milliseconds: 600), bool enableZoom = true, double minZoomScale = 1.0, double maxZoomScale = 4.0, ChartSliceCallback? onSliceHover, ChartSliceCallback? onSliceTap}) -
const
Properties
- animationDuration → Duration
-
final
- emptyStateMessage → String
-
final
- enableAnimation → bool
-
final
- enableZoom → bool
-
Enables pinch/scroll zoom + pan. Set false to disable entirely.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- innerRadiusRatio → double
-
0 = solid pie. 0.5–0.7 is a typical donut hole.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- maxZoomScale → double
-
final
- minZoomScale → double
-
final
- onSliceHover → ChartSliceCallback?
-
Fired continuously as the pointer moves over/off a slice (mouse hover
and touch). Called with
nullwhen nothing is hovered.final - onSliceTap → ChartSliceCallback?
-
Fired once per tap/click on a slice. Not called on taps that miss.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- showLegend → bool
-
final
- showPercentageLabels → bool
-
final
-
slices
→ List<
PieSlice> -
final
- subtitle → String?
-
final
- title → String?
-
final
- valueFormatter → String Function(double value)?
-
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< PieChart2D> -
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, int wrapWidth = 65}) → 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