Skip to main content

Overview

The Sunburst class builds a sunburst diagram where hierarchical data is displayed using nested circular sectors (slices). Each level of hierarchy is represented by a ring, with the root at the center.
import * as am5hierarchy from "@amcharts/amcharts5/hierarchy";

const sunburst = root.container.children.push(
  am5hierarchy.Sunburst.new(root, {
    startAngle: -90,
    endAngle: 270,
    radius: am5.percent(100)
  })
);

Class Hierarchy

  • Series
    • Hierarchy
      • Partition
        • Sunburst

Settings

startAngle

startAngle
number
default:"-90"
Start angle of the series in degrees.
  • 0° is at 3 o’clock
  • -90° is at 12 o’clock (default)
  • 90° is at 6 o’clock
  • 180° is at 9 o’clock
sunburst.set("startAngle", 0);

endAngle

endAngle
number
default:"270"
End angle of the series in degrees.Default is 270° which, combined with startAngle of -90°, creates a full circle.
sunburst.set("endAngle", 180); // Creates a semicircle

innerRadius

innerRadius
number | Percent
default:"0"
Inner radius of the sunburst pie.
  • Can be a fixed pixel value or percent
  • Setting to negative number will mean pixels from outer radius
  • Default of 0 means center starts at middle
sunburst.set("innerRadius", am5.percent(20)); // 20% of radius
sunburst.set("innerRadius", -100); // 100 pixels from outer edge

radius

radius
number | Percent
default:"100%"
Outer radius of the sunburst pie.Can be a fixed pixel value or percent relative to available space.
sunburst.set("radius", am5.percent(90));
sunburst.set("radius", 300); // 300 pixels

nodePadding

nodePadding
number
Padding between slices in pixels.
sunburst.set("nodePadding", 2);

Inherited Settings

Sunburst inherits all settings from Partition and Hierarchy, including:
  • sort - How to sort nodes by value (“ascending” | “descending” | “none”)
  • valueField - Field in data holding numeric value
  • categoryField - Field in data holding category name
  • childDataField - Field in data holding array of children
  • downDepth - Number of child levels to show when drilling down
  • upDepth - Number of parent levels to show from selected node
  • initialDepth - Number of levels to show on first load
  • topDepth - Starting level to show (hides upper levels)
  • singleBranchOnly - Collapse other branches when one expands
  • animationDuration - Duration for drill animations in milliseconds
  • animationEasing - Easing function for animations
  • colors - ColorSet for auto-assigning node colors
  • patterns - PatternSet for auto-assigning node patterns

Data Item Properties

Each data item in a Sunburst chart has the following properties:

children

children
Array<DataItem<ISunburstDataItem>>
Data items of child nodes.

parent

parent
DataItem<ISunburstDataItem>
Data item of a parent node.

slice

slice
Slice
A Slice element of the node.

value

value
number
Value of the node as set in data.

sum

sum
number
Sum of child values.

valuePercentTotal

valuePercentTotal
number
Percent value of the node, based on total sum of all nodes in upper level.

valuePercent

valuePercent
number
Percent value of the node, based on the value of its direct parent.Since: 5.2.21

category

category
string
Category name of the node.

depth

depth
number
Node’s depth within the hierarchy (0 for root).

node

node
HierarchyNode
Reference to the visual HierarchyNode element.

label

label
RadialLabel
Reference to node’s RadialLabel element.

fill

fill
Color
Node’s auto-assigned color.

fillPattern

fillPattern
Pattern
Node’s auto-assigned pattern.Since: 5.10.0

disabled

disabled
boolean
Indicates if node is currently disabled (collapsed).

Data Format

interface ISunburstDataObject {
  name?: string;
  value?: number;
  children?: ISunburstDataObject[];
}

Example Data

sunburst.data.setAll([{
  name: "Root",
  children: [
    {
      name: "Category A",
      children: [
        { name: "A1", value: 100 },
        { name: "A2", value: 60 }
      ]
    },
    {
      name: "Category B",
      children: [
        { name: "B1", value: 135 },
        { name: "B2", value: 98 },
        { name: "B3", value: 56 }
      ]
    },
    {
      name: "Category C",
      children: [
        { name: "C1", value: 78 },
        { name: "C2", value: 43 }
      ]
    }
  ]
}]);

List Templates

Sunburst provides access to these list templates for customization:

nodes

nodes
ListTemplate<HierarchyNode>
List of all node container elements.
sunburst.nodes.template.setAll({
  toggleKey: "disabled"
});

slices

slices
ListTemplate<Slice>
List of node slice elements in the Sunburst chart.
sunburst.slices.template.setAll({
  strokeWidth: 2,
  stroke: am5.color(0xffffff),
  cornerRadius: 4,
  tooltipText: "{category}: {valuePercentTotal.formatNumber('0.00')}%"
});

labels

labels
ListTemplate<RadialLabel>
List of radial label elements.RadialLabel can be rendered as radial or circular text.
sunburst.labels.template.setAll({
  text: "{category}",
  fontSize: 12,
  textType: "radial", // or "circular"
  centerX: 0,
  centerY: 0
});

Containers

nodesContainer

nodesContainer
Container
Container that holds all node elements.For Sunburst, this is centered at 50% x 50% of the chart area.

Methods

selectDataItem()

selectDataItem(dataItem: DataItem<ISunburstDataItem>): void
Selects a specific data item, triggering drill-down animation.
dataItem
DataItem<ISunburstDataItem>
The data item to select.

getDataItemById()

getDataItemById(id: string): DataItem<ISunburstDataItem> | undefined
Looks up and returns a data item by its ID.
id
string
The ID to search for.
return
DataItem<ISunburstDataItem> | undefined
The found data item, or undefined if not found.

enableDataItem()

enableDataItem(
  dataItem: DataItem<ISunburstDataItem>,
  maxDepth?: number,
  depth?: number,
  duration?: number
): void
Enables a disabled (collapsed) data item.
dataItem
DataItem<ISunburstDataItem>
Target data item to enable.
maxDepth
number
Maximum depth to enable children to.
depth
number
Current depth (used internally for recursion).
duration
number
Animation duration in milliseconds.

disableDataItem()

disableDataItem(
  dataItem: DataItem<ISunburstDataItem>,
  duration?: number
): void
Disables (collapses) a data item.
dataItem
DataItem<ISunburstDataItem>
Target data item to disable.
duration
number
Animation duration in milliseconds.

addChildData()

addChildData(
  dataItem: DataItem<ISunburstDataItem>,
  data: Array<any>
): void
Adds children data to the target data item dynamically.
dataItem
DataItem<ISunburstDataItem>
Parent data item to add children to.
data
Array<any>
Array of child data objects.
Since: 5.4.5

hoverDataItem()

hoverDataItem(dataItem: DataItem<ISunburstDataItem>): void
Triggers hover state on a data item.
dataItem
DataItem<ISunburstDataItem>
Target data item.
Since: 5.0.7

unhoverDataItem()

unhoverDataItem(dataItem: DataItem<ISunburstDataItem>): void
Removes hover state from a data item.
dataItem
DataItem<ISunburstDataItem>
Target data item.
Since: 5.0.7

Events

dataitemselected

sunburst.events.on("dataitemselected", (ev) => {
  console.log("Selected:", ev.dataItem);
});
Fired when a data item is selected.
dataItem
DataItem<ISunburstDataItem> | undefined
The selected data item.

Private Settings

These are read-only private settings managed internally:

dr

dr
number
Current radial offset for zoom animation.

dx

dx
number
Current angular offset for zoom animation.

innerRadius

innerRadius
number
Calculated inner radius in pixels.

hierarchySize

hierarchySize
number
Total radial size available for hierarchy levels.

See Also

Build docs developers (and LLMs) love