Back to Fl Chart

Pie Chart

repo_files/documentations/pie_chart.md

1.2.05.5 KB
Original Source

<a href="https://www.youtube.com/watch?v=VlXC-RAaX4Y&list=PL1-_rCwRcnbNpvodmbt43O81wMUdBv8-a"></a>

How to use

dart
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

PropNameDescriptiondefault value
sectionslist of PieChartSectionData that is shown on the pie chart[]
centerSpaceRadiusfree space in the middle of the PieChart, set double.infinity if you want it to be calculated according to the view sizedouble.nan
centerSpaceColorcolors the free space in the middle of the PieChartColors.transparent
sectionsSpacespace between the sections (margin of them). It does not work on html-rendere, read more about it here2
startDegreeOffsetdegree offset of the sections around the pie chart, should be between 0 and 3600
pieTouchDataPieTouchData holds the touch interactivity detailsPieTouchData()
borderDatashows a border around the chart, check the FlBorderDataFlBorderData()
titleSunbeamLayoutwhether to rotate the titles on each section of the chartfalse

PieChartSectionData

PropNameDescriptiondefault value
valuevalue is the weight of each section, for example if all values is 25, and we have 4 section, then the sum is 100 and each section takes 1/4 of the whole circle (360/4) degree10
colorcolors the sectionColors.red
gradientYou can use any Gradient here. such as LinearGradient or RadialGradient (you have to provide either color or gradient)null
radiusthe width radius of each section40
showTitledetermines to show or hide the titles on each sectiontrue
titleStyleTextStyle of the titlesTextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold)
titletitle of the sectionvalue
borderSideDefines border stroke around the sectionBorderSide(width: 0)
cornerRadiusdefines corner radius for rounded section edges0
badgeWidgetbadge component of the sectionnull
titlePositionPercentageOffsetthe place of the title in the section, this field should be between 0 and 10.5
badgePositionPercentageOffsetthe place of the badge component in the section, this field should be between 0 and 10.5

PieTouchData (read about touch handling)

PropNameDescriptiondefault value
enableddetermines to enable or disable touch behaviorstrue
mouseCursorResolveryou can change the mouse cursor based on the provided FlTouchEvent and PieTouchResponseMouseCursor.defer
touchCallbacklisten to this callback to retrieve touch/pointer events and responses, it gives you a FlTouchEvent and PieTouchResponsenull
longPressDurationallows to customize the duration of the longPress gesture. If null, the duration of the longPressGesture is kLongPressTimeoutnull

PieTouchResponse

PropNameDescriptiondefault value
touchLocationthe location of the touch event in the device pixels coordinatesrequired
touchedSectionInstance of PieTouchedSection which holds data about the touched sectionnull

PieTouchedSection

PropNameDescriptiondefault value
touchedSectionthe PieChartSectionData that user touchednull
touchedSectionIndexindex of the touched sectionnull
touchAnglethe angle of the touchnull
touchRadiusthe radius of the touchnull

some samples


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