PhiaUi.Components.DonutChart (phia_ui v0.1.17)

Copy Markdown View Source

Donut chart with a center slot — pure SVG, zero JS.

Uses ring-shaped arc paths (outer + inner radius). Supports a :center slot for custom content (metric value, icon, etc.).

Examples

<.donut_chart data={[
  %{label: "Completed", value: 70},
  %{label: "Pending",   value: 20},
  %{label: "Failed",    value: 10}
]}>
  <:center>70%</:center>
</.donut_chart>

<.donut_chart
  data={[%{label: "Used", value: 80}, %{label: "Free", value: 20}]}
  hole_ratio={0.65}
/>

Summary

Functions

donut_chart(assigns)

Attributes

  • data (:list) (required) - List of %{label, value} (and optional :color).
  • colors (:list) - Override default palette. Defaults to [].
  • hole_ratio (:float) - Ratio of inner radius to outer (0.3–0.8). Controls ring thickness. Defaults to 0.55.
  • show_legend (:boolean) - Defaults to true.
  • animate (:boolean) - Defaults to true.
  • animation_duration (:integer) - Defaults to 600.
  • spacing (:integer) - Gap in pixels between slices (0-8). Defaults to 0.
  • show_link_labels (:boolean) - Show leader lines from slices to external labels. Defaults to false.
  • show_values (:boolean) - Show data values alongside labels in the legend. Defaults to false.
  • active_shape (:boolean) - Enable hover expand effect on slices (Recharts activeShape pattern). Defaults to false.
  • active_expand (:integer) - Radius expansion in px on hover when active_shape is true. Defaults to 6.
  • id (:string) - Unique ID for the chart (auto-generated if not provided). Defaults to nil.
  • title (:string) - Chart title rendered above the visualization. Defaults to nil.
  • description (:string) - Chart description for context (rendered below title). Defaults to nil.
  • class (:string) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • center - Content rendered in the donut center (text, value, etc.).