Skip to main content

Pie Chart

How to use​

PieChart(
PieChartData(
// read about it in the PieChartData section
),
duration: Duration(milliseconds: 150), // Optional
curve: Curves.linear, // Optional
);

If you have a padding widget around the PieChart, make sure to set PieChartData.centerSpaceRadius to double.infinity

Implicit Animations​

When you change the chart's state, it animates to the new state internally (using implicit animations). You can control the animation duration and curve using optional duration and curve properties, respectively.

PieChartData​

sectionsList<PieChartSectionData>?#defaultconst []

Defines showing sections of the PieChart.

centerSpaceRadiusdouble?#defaultdouble.infinity

Radius of free space in center of the circle.

If it's not finite (like double.infinity), it is calculated from the size of the chart.

centerSpaceColorColor?#defaultColors.transparent

Color of free space in center of the circle.

sectionsSpacedouble?#default2

Defines gap between sections.

Does not work on html-renderer, https://github.com/imaNNeo/fl_chart/issues/955

startDegreeOffsetdouble?#default0

PieChart draws sections from zero degree (right side of the circle) clockwise.

pieTouchDataPieTouchData?#defaultPieTouchData()

Handles touch behaviors and responses.

borderDataFlBorderData?#defaultFlBorderData(show: false)

Holds data to draw the border around the chart, see FlBorderData.

titleSunbeamLayoutbool?#defaultfalse

Whether to rotate the titles on each section of the chart

PieChartSectionData​

valuedouble?#default10

It determines how much space it should occupy around the circle.

This is depends on sum of all sections, each section should occupy (value / sumValues) * 360 degrees.

value can not be null.

colorColor?#defaultColors.cyan

Defines the color of section.

gradientGradient?#defaultnull

Defines the gradient of section. If specified, overrides the color setting.

radiusdouble?#default40

Defines the radius of section.

showTitlebool?#defaulttrue

Defines show or hide the title of section.

titleStyleTextStyle?#defaultnull

Defines style of showing title of section, merged with the text style of the theme.

titleString?#

Defines text of showing title at the middle of section.

Defaults to the value of the section, if it is provided.

borderSideBorderSide?#defaultconst BorderSide(width: 0)

Defines border stroke around the section

cornerRadiusdouble?#default0.0

Defines corner radius for rounded edges (applies to all corners)

badgeWidgetWidget?#defaultnull

Defines a widget that represents the section.

This can be anything from a text, an image, an animation, and even a combination of widgets. Use AnimatedWidgets to animate this widget.

titlePositionPercentageOffsetdouble?#default0.5

Defines position of showing title in the section.

It should be between 0.0 to 1.0, 0.0 means near the center, 1.0 means near the outside of the PieChart.

badgePositionPercentageOffsetdouble?#default0.5

Defines position of badge widget in the section.

It should be between 0.0 to 1.0, 0.0 means near the center, 1.0 means near the outside of the PieChart.

segmentsList<PieChartStackSegmentData>?#defaultconst []

Stacked segments rendered on top of the main section.

Each segment defines PieChartStackSegmentData.fromRadius and PieChartStackSegmentData.toRadius to specify its position within the section's radius. Values are clamped to [0, radius] at render time.

PieChartStackSegmentData​

fromRadiusdouble?#default0

The start radius of this segment (distance from center of the section). Clamped to [0, sectionRadius] at render time.

toRadiusdouble#required

The end radius of this segment (distance from center of the section). Clamped to [0, sectionRadius] at render time.

colorColor?#defaultColors.purple

Defines the color of segment.

gradientGradient?#defaultnull

Defines the gradient of segment. If specified, overrides the color setting.

PieTouchData (read about touch handling)​

enabledbool?#defaulttrue

Determines whether to enable or disable touch behaviors.

touchCallbackvoid Function(FlTouchEvent, PieTouchResponse?)?#defaultnull

touchCallback notifies you about the happened touch/pointer events. It gives you a FlTouchEvent which is the happened event such as FlPointerHoverEvent, FlTapUpEvent, ... It also gives you a BaseTouchResponse which is the chart specific type and contains information about the elements that has touched.

mouseCursorResolverMouseCursor Function(FlTouchEvent, PieTouchResponse?)?#defaultnull

Using mouseCursorResolver you can change the mouse cursor based on the provided FlTouchEvent and BaseTouchResponse

longPressDurationDuration?#defaultnull

This property that allows to customize the duration of the longPress gesture. If null, it uses kLongPressTimeout (500 milliseconds).

PieTouchResponse​

touchLocationOffset#

The location of the touch in pixels on the screen.

touchedSectionPieTouchedSection?#

Contains information about touched section, like index, angle, radius, ...

PieTouchedSection​

touchedSectionPieChartSectionData?#

The touched section, null if no section is touched.

touchedSectionIndexint#

The index of touchedSection in PieChartData.sections, -1 if no section is touched.

touchAngledouble#

The angle of the touch around the center of the PieChart, in degrees.

touchRadiusdouble#

The distance of the touch from the center of the PieChart.

some samples​


Sample 1 (Source Code)​
Sample 2 (Source Code)​
Sample 3 (Source Code)​