PieChart class
Chart that draws one PieData set as slices of a circle. Slice sizes are shares of the sum of all absolute y values; the first slice starts at rotationAngle and slices follow clockwise. Angles are in degrees.
- Inheritance
-
- Object
- Chart<
PieData> - PieRadarChartBase<
PieData> - PieChart
Constructors
- PieChart()
Properties
- absoluteAngles → Float32List
-
End angle of each slice in degrees, measured from rotationAngle, in entry order; one 0 before any data.
no setter
-
afterDrawListeners
→ List<
void Function()> -
Called at the end of every onDraw, in list order: after the markers, or after the empty state.
finalinherited
- animator ↔ ChartAnimator
-
Runs the animations: the x and y phases of animateX, animateY and animateXY, and the value animations.
getter/setter pairinherited
- center → MPPointF
-
Center of the whole chart in pixels, ignoring offsets. See centerOffsets for the content center.
no setterinherited
- centerCircleBox → MPPointF
-
Center of circleBox in pixels, as a new point.
no setter
- centerOffsets → MPPointF
-
Center of the content rectangle in pixels, as a fresh MPPointF.
no setterinherited
- centerOfView → MPPointF
-
Center of the whole chart view in pixels, as a fresh MPPointF.
no setterinherited
- centerText ↔ String
-
Text drawn in the center of the pie while isDrawCenterTextEnabled is true. Default empty.
getter/setter pair
- centerTextColor ↔ Color
-
Color of centerText. Default black.
getter/setter pair
- centerTextOffset → MPPointF
-
Copy of the shift set with setCenterTextOffset, in dp.
no setter
- centerTextPaint ↔ ChartPaint
-
Paint used for the center text, the renderer's
paintCenterText.getter/setter pair - centerTextRadiusPercent ↔ double
-
Width of the box centerText wraps in, as a percentage of the hole diameter. Default 100.
getter/setter pair
- centerTextSize ↔ double
-
Text size of centerText in dp. Default 12.
getter/setter pair
- centerTextTypeface ↔ Typeface
-
Typeface of centerText; null sets the default.
getter/setter pair
-
chartTouchListener
↔ ChartTouchListener<
Chart< ChartData< >IDataSet< >Entry> > -
Handles touch events for this chart. Replace it to customize gestures; isTouchEnabled must stay true.
getter/setter pairinherited
- circleBox → MutableRect
-
Bounds of the pie in pixels, already shrunk by the data set's selection shift. Set by calculateOffsets.
final
- contentRect → MutableRect
-
Rectangle in pixels in which the data is drawn, the view minus axis, legend and extra offsets.
no setterinherited
- data ↔ PieData?
-
The data this chart displays, or null when nothing has been set.
getter/setter pairinherited
- defaultValueFormatter → IValueFormatter
-
Formatter the chart computed from its data, used by data sets that have no formatter of their own.
no setterinherited
- defaultValueFormatterInternal → DefaultValueFormatter
-
Formatter used for data sets without their own. Its digit count follows the y range of the data.
finalinherited
- description ↔ Description
-
The description text drawn in the bottom right corner by default.
getter/setter pairinherited
- descriptionPaint ↔ ChartPaint
-
Paint used for the description text.
getter/setter pairinherited
- diameter → double
-
Largest circle diameter in pixels that fits the content area after the extra offsets.
no setterinherited
- dragDecelerationFrictionCoef ↔ double
-
How slowly a deceleration scroll loses speed, between 0 (stops at once) and 0.999.
Values outside that range are clamped. Default 0.9.
getter/setter pairinherited
- drawAngles → Float32List
-
Size of each slice in degrees, in entry order. Recomputed whenever the data changes (by notifyDataSetChanged);
one 0 before any data.
no setter
- entryLabelColor ↔ Color
-
Color of the entry labels drawn at the slices. Default white.
getter/setter pair
- entryLabelTextSize ↔ double
-
Text size in dp of the entry labels drawn at the slices. Default 13.
getter/setter pair
- entryLabelTypeface ↔ Typeface
-
Typeface of the entry labels drawn at the slices; null sets the default.
getter/setter pair
- extraBottomOffset ↔ double
-
Extra space in dp added below the content area on top of the calculated offsets.
getter/setter pairinherited
- extraLeftOffset ↔ double
-
Extra space in dp added left of the content area on top of the calculated offsets.
getter/setter pairinherited
- extraRightOffset ↔ double
-
Extra space in dp added right of the content area on top of the calculated offsets.
getter/setter pairinherited
- extraTopOffset ↔ double
-
Extra space in dp added above the content area on top of the calculated offsets.
getter/setter pairinherited
-
gestureListeners
→ List<
OnChartGestureListener> -
Additional gesture listeners, notified after onChartGestureListener in list order.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- height ↔ double
-
Height of the chart in logical pixels,
View.getHeight(). Set by onSizeChanged.getter/setter pairinherited -
highlighted
↔ List<
Highlight> -
The values currently highlighted. Empty, never null, when nothing is highlighted.
getter/setter pairinherited
- highlighter ↔ IHighlighter
-
Turns a touch position into the Highlight of the nearest value.
getter/setter pairinherited
- holeColor ↔ Color
-
Fill color of the hole, used while isDrawHoleEnabled is true. Default white; a fully transparent color
leaves the hole empty.
getter/setter pair
- holePaint ↔ ChartPaint
-
Paint used for the hole in the middle of the pie, the renderer's
paintHole.getter/setter pair - holeRadius ↔ double
-
Radius of the hole as a percentage of the pie radius. Default 50.
getter/setter pair
- host ↔ ChartHost?
-
What shows this chart on screen and receives its redraw, post and scroll requests, or null. The widget layer's
render object assigns itself here while it is attached.
getter/setter pairinherited
- infoPaint ↔ ChartPaint
-
Paint used for the no-data text.
getter/setter pairinherited
- isAnimating → bool
-
True while any animation runs: animateX, animateY, animateXY, a spin, animateValue or animateDataChange.
no setterinherited
- isChartTouchListenerInitialized → bool
-
Whether chartTouchListener has been assigned, Kotlin's
::chartTouchListener.isInitialized.no setterinherited - isDragDecelerationEnabled ↔ bool
-
Whether the chart keeps scrolling after the finger is lifted.
getter/setter pairinherited
- isDrawCenterTextEnabled ↔ bool
-
Whether centerText is drawn. Default true.
getter/setter pair
- isDrawEntryLabelsEnabled ↔ bool
-
Whether the label of each
PieEntryis drawn at its slice. Default true.getter/setter pair - isDrawHoleEnabled ↔ bool
-
Whether the hole in the center is drawn. Default true.
getter/setter pair
- isDrawMarkersEnabled ↔ bool
-
Whether the marker is drawn at highlighted values.
getter/setter pairinherited
- isDrawRoundedSlicesEnabled ↔ bool
-
Whether slice ends are rounded. Only applies with the hole drawn and slices not under the hole. Default false.
getter/setter pair
- isDrawSlicesUnderHoleEnabled ↔ bool
-
Whether the slices continue under the hole instead of stopping at its edge. Default false.
getter/setter pair
- isEmpty → bool
-
True when there is no data or the data holds no entries.
no setterinherited
- isHighlightPerTapEnabled ↔ bool
-
Whether a tap highlights the nearest value. Values can still be highlighted by drag or in code.
getter/setter pairinherited
- isLoading ↔ bool
-
Whether the data is on its way. While true and the chart has nothing to draw, the empty state shows
loadingText and its icon pulses. Data that arrives is drawn as usual, so this can stay true until then.
getter/setter pairinherited
- isLogEnabled ↔ bool
-
Prints chart internals with
debugPrintwhile true. Slows down drawing, so keep it off in production.getter/setter pairinherited - isNoDataIconEnabled ↔ bool
-
Whether the empty state draws an icon above its text: noDataIcon, or a small outline of this chart type.
getter/setter pairinherited
- isRendererInitialized → bool
-
Whether renderer has been assigned, Kotlin's
::renderer.isInitialized.no setterinherited - isRotationEnabled ↔ bool
-
Whether the chart can be rotated by dragging. Default true.
getter/setter pairinherited
- isRoundedSlicesReversed ↔ bool
-
Whether rounded slice ends point counter-clockwise instead of clockwise: each slice then bulges out at its
start and is hollowed at its end. Only applies with isDrawRoundedSlicesEnabled. Default false.
getter/setter pair
- isTouchEnabled ↔ bool
-
Whether the chart reacts to touch at all. False disables tapping, dragging, scaling and rotating.
getter/setter pairinherited
- isTransparentCircleClippedToSlices ↔ bool
-
Whether the translucent ring around the hole is drawn only over the slices, so that it tints each slice and
leaves the slice space between them clear. Default false, which draws one closed ring.
getter/setter pair
- isUnbindEnabled ↔ bool
-
Kept for API parity; it has no effect. On Android it releases the background drawable and the child views when
the chart leaves the window; a Flutter chart has neither.
getter/setter pairinherited
- isUsePercentValuesEnabled ↔ bool
-
Whether values are handed to the value formatter as a percentage of the total instead of as is. Default false.
getter/setter pair
-
jobs
→ List<
void Function()> -
Viewport jobs waiting for the chart to get a size. They run once in onSizeChanged.
finalinherited
- legend ↔ Legend
-
The legend component. It is filled from the data sets unless a custom legend is set on it.
getter/setter pairinherited
- legendLabelPaint ↔ ChartPaint
-
Paint used for legend labels.
getter/setter pairinherited
- legendRenderer ↔ LegendRenderer
-
Draws the legend.
getter/setter pairinherited
- loadingText ↔ String
-
Text of the empty state while isLoading is true.
getter/setter pairinherited
- marker ↔ IMarker?
-
Marker drawn at each highlighted value, or null for none.
A MarkerView or MarkerImage is attached to this chart when set.
getter/setter pairinherited
- maxAngle ↔ double
-
Angle in degrees the whole pie spans, clamped to 90 until 360. 360 is a full circle, 180 a half pie.
Default 360.
getter/setter pair
- maxHighlightDistance ↔ double
-
Farthest distance in dp a touch may be from a value and still highlight it. Default 500.
getter/setter pairinherited
- maxVisibleCount → int
-
The number of entries of the data, or 0 without data.
no setterinherited
- minAngleForSlices ↔ double
-
Smallest angle in degrees a slice is drawn with, clamped to 0 until half of maxAngle. Only applied when all
slices fit at that size; call notifyDataSetChanged after changing it. Default 0.
getter/setter pair
- minOffset ↔ double
-
Smallest space in dp between the view edge and the chart on every side. Default 0.
getter/setter pairinherited
- noDataIcon ↔ ChartDrawable?
-
Icon drawn above the empty state text instead of the outline of this chart type, or null for the outline.
getter/setter pairinherited
- noDataIconColor ↔ Color
-
Color of the chart type outline in the empty state. Default a faint slate that reads on light and dark backgrounds.
getter/setter pairinherited
- noDataText ↔ String
-
Text of the empty state, drawn while the chart has no data or data without entries. An empty string draws
only the icon.
getter/setter pairinherited
- noDataTextAlignment ↔ PaintAlign
-
Horizontal alignment of the empty state: at the left edge, in the center or at the right edge of the chart.
getter/setter pairinherited
- noDataTextColor ↔ Color
-
Color of noDataText and loadingText.
getter/setter pairinherited
- noDataTextSize ↔ double
-
Size of noDataText and loadingText in dp. Default 13.
getter/setter pairinherited
- noDataTextTypeface ↔ Typeface
-
Typeface of noDataText and loadingText; null sets the default. Default sans serif medium.
getter/setter pairinherited
- onChartGestureListener ↔ OnChartGestureListener?
-
Single listener told about gestures such as tap, double tap, drag, scale and fling.
getter/setter pairinherited
- onChartValueSelectedListener ↔ OnChartValueSelectedListener?
-
Single listener told when a value is selected or the selection is cleared.
getter/setter pairinherited
- radius → double
-
Radius of the pie in pixels: half the smaller side of circleBox.
no setteroverride
- rawRotationAngle → double
-
The last value given to rotationAngle before normalizing, in degrees, which may be negative or above 360.
Default 270.
no setterinherited
- renderer ↔ DataRenderer
-
Draws the data. Each chart type installs its own renderer; replace it for custom drawing.
getter/setter pairinherited
- requiredBaseOffset → double
-
Always 0: a pie needs no room beside itself.
no setteroverride
- requiredLegendOffset → double
-
Twice the legend text size in pixels.
no setteroverride
- requiredVerticalBaseOffset → double
-
Space in pixels the chart needs above and below itself before the legend is considered. The same as
requiredBaseOffset unless a chart needs less room there, as a radar chart does: its labels reach as far
sideways as they are wide, but only as far up and down as they are tall.
no setterinherited
- rotationAngle ↔ double
-
Angle in degrees at which the first slice or entry starts, normalized to 0 (inclusive) until 360 (exclusive).
Default 270, the top of the chart. Setting it also stores the unnormalized value in rawRotationAngle.
getter/setter pairinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- showsEmptyState → bool
-
Whether the chart has no data or no entries and draws its empty state instead of the data.
no setterinherited
- transparentCircleAlpha ↔ int
-
Opacity of the translucent ring from 0 (invisible) to 255 (opaque). Default 105.
getter/setter pair
- transparentCircleColor ↔ Color
-
Color of the translucent ring around the hole. Setting it keeps the current transparentCircleAlpha. Default
white.
getter/setter pair
- transparentCircleRadius ↔ double
-
Radius of the translucent ring around the hole as a percentage of the pie radius. Default 55.
The ring is only drawn while this is larger than holeRadius.
getter/setter pair
-
valueSelectedListeners
→ List<
OnChartValueSelectedListener> -
Additional listeners, notified after onChartValueSelectedListener in list order.
Meant for observers that must not replace the app's own listener, such as a widget's chart controller.
finalinherited
- viewPortHandler ↔ ViewPortHandler
-
Holds the chart size, the content rectangle and the zoom and drag matrix.
getter/setter pairinherited
- width ↔ double
-
Width of the chart in logical pixels,
View.getWidth(). Set by onSizeChanged.getter/setter pairinherited - xAxis ↔ XAxis
-
The x axis component: its labels, range, grid lines and position.
getter/setter pairinherited
- xChartMax → double
-
Largest x value of the x axis, independent of zoom and drag.
no setterinherited
- xChartMin → double
-
Smallest x value of the x axis, independent of zoom and drag.
no setterinherited
- xRange → double
-
Difference between xChartMax and xChartMin.
no setterinherited
- yChartMax → double
-
Always 0: a round chart has no y axis.
no setterinherited
- yChartMin → double
-
Always 0: a round chart has no y axis.
no setterinherited
- yMax → double
-
Largest y value across all data sets, or 0 without data.
no setterinherited
- yMin → double
-
Smallest y value across all data sets, or 0 without data.
no setterinherited
Methods
-
addViewportJob(
void job()) → void -
Runs a viewport job once the chart has a size: posted right away when it already has one, otherwise stored
in jobs until onSizeChanged. The zoom and move functions use this, passing a job's
run. At most 64 jobs wait, because only the last position matters and a chart that never gets a size would otherwise collect them forever.inherited -
animateDataChange(
PieData newData, int durationMillis, {EasingFunction easing = Easing.Linear, void onEnd() = _noop}) → void -
Sets
newDataand animates every entry from the value it replaces to its own value. Entries are paired by data set index and entry index; entries past the old end grow from 0, entries past the new end are gone at once. Stacked bars animate each stack value, candles open, high, low and close, bubbles their size and pie slices their value. The axis ranges follow on every frame and highlights stay on their x value.inherited -
animateValue(
Entry entry, double toY, int durationMillis, {EasingFunction easing = Easing.Linear, void onEnd() = _noop}) → void -
Animates the y value of one entry to
toY. The axis ranges follow the value on every frame. Works for line, bar, scatter, bubble, pie and radar entries. A running animation of the same entry is cancelled first and the new one starts from the current value. Setting data ends the animation with the entry attoY.inherited -
animateX(
int durationMillis, {EasingFunction easing = Easing.Linear, void onEnd() = _noop}) → void -
Animates the drawing of the data along the x axis. The chart redraws itself while animating. A running x
animation is cancelled first.
inherited
-
animateXY(
int durationMillisX, int durationMillisY, {EasingFunction easingX = Easing.Linear, EasingFunction? easingY, void onEnd() = _noop}) → void -
Animates the drawing of the data along both axes. The chart redraws itself while animating. Running x and y
animations are cancelled first.
inherited
-
animateY(
int durationMillis, {EasingFunction easing = Easing.Linear, void onEnd() = _noop}) → void -
Animates the drawing of the data along the y axis. The chart redraws itself while animating. A running y
animation is cancelled first.
inherited
-
calcMinMax(
) → void -
Computes drawAngles and absoluteAngles from the data.
override
-
calculateOffsets(
) → void -
Also sets circleBox: the largest centered square of the content area, shrunk by the selection shift of the
data set on every side.
override
-
clear(
) → void -
Sets data to null, clears the highlight and redraws, which shows noDataText.
inherited
-
clearAllViewportJobs(
) → void -
Drops all jobs waiting in jobs.
inherited
-
clearValues(
) → void -
Removes all data sets from data but keeps the data object, then redraws. Does nothing without data.
inherited
-
computeScroll(
) → void -
Advances the rotation deceleration of the chartTouchListener by one frame.
inherited
-
disableScroll(
) → void -
Keeps the current gesture with the chart, so an enclosing scrollable does not take it over
(
requestDisallowInterceptTouchEvent(true)on Android).inherited -
distanceToCenter(
double x, double y) → double -
Distance in pixels between the pixel position (
x,y) and the content center.inherited -
drawDescription(
Canvas c) → void -
Draws the description text at its position, or in the bottom right corner when it has none.
inherited
-
drawEmptyState(
Canvas canvas) → void -
Draws the empty state: the icon and noDataText, or loadingText while isLoading, as one block centered
vertically and placed horizontally by noDataTextAlignment. Override it to draw an empty state of your own.
inherited
-
drawMarkers(
Canvas canvas) → void -
Draws the marker at every highlighted value that lies inside the content area.
inherited
-
drawNoDataIcon(
Canvas canvas, MutableRect bounds, ChartPaint paint) → void -
Draws a ring, the outline of a pie, inside
boundsfor the empty state.override -
enableScroll(
) → void -
Lets an enclosing scrollable take over gestures again (
requestDisallowInterceptTouchEvent(false)on Android).inherited -
getAngleForPoint(
double x, double y) → double -
Angle in degrees of the pixel position (
x,y) around the content center: 0 at 3 o'clock, 90 at 6 o'clock, 180 at 9 o'clock, 270 at 12 o'clock; from 0 (inclusive) to 360 (exclusive) for a finite position. The center itself yields 90.inherited -
getDataSetIndexForIndex(
int xIndex) → int - Index of the data set that holds an entry at the given x value.
-
getHighlightByTouchPoint(
double x, double y) → Highlight? -
Finds the value nearest to a touch position.
inherited
-
getIndexForAngle(
double angle) → int -
Index of the slice lying under
anglein degrees (0 at 3 o'clock, increasing clockwise), taking rotationAngle into account, or -1 when no slice lies under it (beyond maxAngle or without data).override -
getMarkerPosition(
Highlight high) → Float32List -
Pixel position of the marker for
high: on the bisector of its slice, halfway between the hole edge and the rim (with the hole) or 3.6 tenths of the radius in from the rim (without).[NaN, NaN]whenhighis not a slice.override -
getPosition(
MPPointF center, double dist, double angle, [MPPointF? outputPoint]) → MPPointF -
Pixel position at the distance
distin pixels and the angleanglein degrees (0 at 3 o'clock, increasing clockwise) from the pointcenterin pixels.inherited -
highlightValue(
double x, int dataSetIndex, {double y = double.nan, int dataIndex = -1, int stackIndex = -1, bool callListener = true}) → void -
Highlights the entry closest to the given x value (and, when
yis a number, closest toyamong entries with the same x) in one data set and redraws.inherited -
highlightValueOf(
Highlight? highlight, {bool callListener = true}) → void -
Highlights the value described by
highlightand redraws. This is what a tap calls. Null, or a highlight that matches no entry, clears the highlight instead.inherited -
highlightValues(
List< Highlight> highs) → void -
Highlights all the given values at once and redraws. The list is taken as is, without checking that
the entries exist, and no listener is called. An empty list clears the highlight.
inherited
-
init(
) → void -
Creates the components, paints and animator. Subclasses add their renderer, highlighter and touch listener.
override
-
invalidate(
) → void -
Requests a redraw from the host,
View.invalidate(). Does nothing without a host.inherited -
needsHighlight(
int index) → bool -
True when the slice at
indexis currently highlighted. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyAfterDraw(
) → void -
Calls each of afterDrawListeners. onDraw calls it once at its very end; a chart type that overrides onDraw
and draws after
super.onDrawcalls it at the end of its own onDraw instead, asBarLineChartBase,PieChartandRadarChartdo.inherited -
notifyDataSetChanged(
) → void -
Refreshes the data, recalculates axis ranges, legend and offsets and redraws.
Call it after changing entries or data sets in place. Does nothing while data is null.
inherited
-
onDetachedFromWindow(
) → void -
Releases the renderer's cached center text layout, where Kotlin released its offscreen bitmap, then does what
every round chart does when its host goes away (stops the rotation deceleration and running animations).
override
-
onDraw(
Canvas canvas) → void -
Draws the slices, the highlighted slices, the hole and the center text, the values and labels, the legend, the
description and the markers, in that order, or the empty state while there is nothing to draw.
override
-
onHostVsyncChanged(
) → void -
Also stops a running rotation deceleration, whose ticker runs on the previous vsync. Not in Kotlin.
inherited
-
onSizeChanged(
double w, double h) → void -
Sets the chart size to
wxh,View.onSizeChanged: the host calls it when the laid out size changes.inherited -
onTouchEvent(
ChartTouchEvent event) → bool -
Passes
eventto the chartTouchListener while isTouchEnabled is true and a listener is assigned, and returns what it returns; otherwise consumes nothing.inherited -
onValueSelected(
void onValueSelected(Entry entry, Highlight highlight), {void onNothingSelected() = _noop}) → void -
Replaces onChartValueSelectedListener with functions.
inherited
-
post(
void job()) → void -
Runs
jobafter the current frame through the host,View.post(Runnable), or at once without a host.inherited -
removeViewportJob(
void job()) → void -
Removes a job from jobs before it has run.
inherited
-
setCenterTextOffset(
double x, double y) → void - Moves centerText away from the center of the pie.
-
setExtraOffsets(
double left, double top, double right, double bottom) → void -
Sets all four extra offsets in dp at once. They apply on the next offset calculation.
inherited
-
setLastHighlighted(
List< Highlight> ? highs) → void -
Tells the touch listener which highlight a tap must toggle off next.
inherited
-
setupDefaultFormatter(
double min, double max) → void -
Sets the digit count of the default value formatter from the value range.
inherited
-
spin(
int durationMillis, double fromAngle, double toAngle, {EasingFunction easing = Easing.Linear, void onEnd()?}) → void -
Animates rotationAngle from one angle to another and redraws on every step. A running spin is cancelled
first.
inherited
-
stopAnimations(
) → void -
Ends every running animation at once at its final state: the drawing is complete, a spin stands at its end
angle and animated values hold their targets. Each
onEndruns. Leaving the window does the same.inherited -
toImage(
{int? width, int? height, double pixelRatio = 1.0}) → Future< Image> -
Draws the chart into a new image, over white. Kotlin's
toBitmap.inherited -
toPngBytes(
{int? width, int? height, double pixelRatio = 1.0}) → Future< Uint8List> -
Draws the chart like toImage and encodes the image as PNG.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
valuesToHighlight(
) → bool -
True when at least one value is highlighted.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited