Pie Chart

Animated inline-SVG pie and donut chart with configurable legend, percentage labels, and color palette. 1 control, 13 properties. Renders entirely in a single Image control via data:image/svg+xml.

cmpPieChart.yaml

Import via Components β†’ New component β†’ Import from code β†’ paste YAML

Preview

Budget Allocation35%28%22%15%Marketing35.0%Sales28.0%Engineering22.0%Operations15.0%

Installation

This component requires Modern controls to be enabled. Settings β†’ Updates β†’ Preview β†’ Modern controls and themes

# In Power Apps Studio:
1. Components tab β†’ New component β†’ Import from code
2. Paste the full YAML definition
3. Add the component to any screen
4. Press F5 (Preview) to trigger the entry animation

Usage

Basic pie chart

// ChartData: one row per slice with Label, Value, optional Color
cmpPieChart.ChartData = Table(
    { Label: "Marketing",  Value: 35000, Color: "#3B82F6" },
    { Label: "Sales",      Value: 28000, Color: "#10B981" },
    { Label: "Engineering", Value: 22000, Color: "#F59E0B" },
    { Label: "Operations", Value: 15000, Color: "#EF4444" }
)

cmpPieChart.ChartTitle = "Budget Allocation"
cmpPieChart.ShowPercentages = true
cmpPieChart.ShowLegend = true

Donut chart from data source

// Shape data into Label + Value + Color rows
cmpPieChart.ChartData =
    AddColumns(
        GroupBy(SalesData, "Region", "Sales"),
        "Label", Region,
        "Value", Sum(Sales, Amount),
        "Color", Switch(
            Region,
            "North", "#3B82F6",
            "South", "#10B981",
            "East",  "#F59E0B",
            "West",  "#8B5CF6",
            "#6B7280"
        )
    )

cmpPieChart.ChartTitle = "Sales by Region"
cmpPieChart.DonutMode = true
cmpPieChart.DonutThickness = 0.7

Dark theme, custom palette

cmpPieChart.Theme = "Dark"
cmpPieChart.Animate = true
cmpPieChart.ShowValues = true
cmpPieChart.ShowPercentages = true

// Custom color palette (used when Color column is blank)
cmpPieChart.DefaultColors = Table(
    { Color: "#1E40AF" },
    { Color: "#3B82F6" },
    { Color: "#60A5FA" },
    { Color: "#93C5FD" }
)

Properties

Input

PropertyTypeDefault
ChartData

Table with Label (text), Value (number), and optional Color (text) columns. One row per slice.

Table4-item sample
ChartTitle

Title text rendered at the top-left of the SVG.

Text"Budget Allocation"
DefaultColors

Fallback color palette when Color column is blank. Cycles via Mod().

Table8-color palette
DonutMode

Render as donut chart with center hole.

Booleanfalse
DonutThickness

Thickness of donut ring. 0.3 = thin ring, 0.9 = nearly full pie.

Number0.6
ShowLabels

Show text labels on slices. Only rendered for slices β‰₯ 5%.

Booleantrue
ShowLegend

Show legend with color swatches on the right side.

Booleantrue
ShowPercentages

Show percentage values on slice labels and in legend.

Booleantrue
ShowTitle

Show the ChartTitle text.

Booleantrue
ShowValues

Show actual numeric values in the legend.

Booleanfalse
Theme

"Light" or "Dark". Controls background, title, legend, and empty state colors.

Text"Light"
Animate

Enable slice fade-in animation with staggered delays.

Booleantrue
AnimationDuration

Duration of each slice’s animation in seconds.

Number0.8

No output properties or events β€” the component is purely visual (SVG rendering). 13 input properties total.

Data Schema

ChartData record

FieldTypeNotes
LabelTextSlice label. Displayed in legend and optionally on the slice itself.
ValueNumberNumeric value. The chart auto-calculates percentages from Sum(Data, Value).
ColorText (optional)Hex color string (e.g. "#3B82F6"). Falls back to DefaultColors palette if blank.

DefaultColors record

FieldTypeNotes
ColorTextHex color string. Palette cycles via Mod(idx - 1, CountRows(Colors)) + 1.

Implementation Details

Single-control SVG rendering

The entire chart is a single Image control generating a data:image/svg+xml URI. No dependencies β€” works anywhere Power Apps renders images, including galleries and PDF exports.

Slice geometry

Each slice is an SVG <path> using arc commands. Start angles accumulate from -90Β° (12 o'clock). The large-arc-flag switches at 180Β°. A single-slice 100% case (sweep β‰₯ 359.9) falls back to a full <circle> since SVG arcs can't draw a complete ring.

Donut mode

When DonutMode = true, paths become ring arcs: outer arc forward, inner arc backward, forming closed annular sectors. The inner radius is radius Γ— (1 - DonutThickness). Labels position at the midpoint of the ring: (radius + innerR) / 2.

Color resolution

Each slice first checks its own Color column. If blank, it indexes into DefaultColors with modular cycling: Mod(idx - 1, CountRows(Colors)) + 1. This means 12 slices with an 8-color palette will wrap and reuse.

Animation system

Three CSS @keyframes injected via <style> when Animate is on:pieGrow (scale 0β†’1 for single-slice),sliceFade (opacity + scale, staggered at 0.08s intervals), andlabelFade (delayed until half-way through slice animation).

Label visibility threshold

Slice labels only render when percent β‰₯ 5. This prevents overlapping text on tiny slices. When ShowPercentages is on, labels show the rounded percentage; otherwise they show the Label text.

Limitations

No interactive tooltips (inline SVG in Image controls doesn't support hover events). Legend is fixed to the right side β€” the pie repositions from center to cx=200 when legend is on. Empty state renders a centered β€œNo data” message when ChartData is empty or total is zero.

Examples

Default: Budget allocation (pie)

Budget Allocation35%28%22%15%Marketing35 (35.0%)Sales28 (28.0%)Engineering22 (22.0%)Operations15 (15.0%)
cmpPieChart.ChartData = Table(
    {Label:"Marketing",Value:35,Color:"#3B82F6"},
    {Label:"Sales",Value:28,Color:"#10B981"},
    {Label:"Engineering",Value:22,Color:"#F59E0B"},
    {Label:"Operations",Value:15,Color:"#EF4444"}
)
cmpPieChart.ChartTitle = "Budget Allocation"
cmpPieChart.ShowPercentages = true
cmpPieChart.ShowValues = true
cmpPieChart.DonutMode = false

Dark donut: Sales by region

Sales by Region42%28%18%12%North42.0%South28.0%East18.0%West12.0%
cmpPieChart.Theme = "Dark"
cmpPieChart.DonutMode = true
cmpPieChart.DonutThickness = 0.6
cmpPieChart.ChartTitle = "Sales by Region"
cmpPieChart.ShowPercentages = true

Minimal: no legend, title, or values

45%32%15%8%
// Minimal donut β€” labels only
cmpPieChart.ShowTitle = false
cmpPieChart.ShowLegend = false
cmpPieChart.ShowValues = false
cmpPieChart.ShowLabels = true
cmpPieChart.DonutMode = true

Architecture

1 control β€” a single Image control rendering an inline SVG via EncodeUrl().

13 properties β€” all input. No output properties or events.

Default size β€” App.Width Γ— 400px. SVG viewBox is 700 Γ— 350.

cmpPieChart (App.Width Γ— 400, Fill: transparent)
└── imgPieChart (Image control)
    └── Image = "data:image/svg+xml," & EncodeUrl(svg)

    SVG structure (viewBox 700Γ—350):
    β”œβ”€β”€ <style> @keyframes (conditional on Animate)
    β”œβ”€β”€ <text> ChartTitle (top-left, conditional on ShowTitle)
    β”œβ”€β”€ For each slice in ChartData:
    β”‚   β”œβ”€β”€ <path> Pie slice (or donut ring arc)
    β”‚   β”‚   └── style: sliceFade animation (staggered 0.08s)
    β”‚   └── <text> Percentage/label (conditional: ShowLabels && pct β‰₯ 5%)
    β”œβ”€β”€ <circle> Donut center hole (conditional on DonutMode)
    └── Legend (conditional on ShowLegend, positioned at x=380):
        └── For each slice:
            β”œβ”€β”€ <rect rx=3> Color swatch
            β”œβ”€β”€ <text> Label name
            └── <text> Value / percentage