# Sunburst 101

This page shows how to get started with Wijmo's Sunburst chart control.

## Getting Started

Here are the steps for getting started with the Sunburst chart control in JavaScript applications:

1. Add references to Wijmo.
2. Add markup to serve as the Wijmo control's host.
3. Initialize the Wijmo control(s) via JavaScript.
4. (Optional) Add some CSS to customize the control's appearance.

HTML
<div id="introChart"></div>
JS
var introChart = new wijmo.chart.hierarchical.Sunburst('#introChart', { binding: 'value', bindingName: ['year', 'quarter', 'month'], itemsSource: getData(), dataLabel: { position: 'Center', content: '{name}' } });

#### Result (live):

## Grouped CollectionView

This sample shows how to use the Sunburst chart with Grouped CollectionView data sources.

HTML
<div id="groupCVChart"></div>
JS
var groupCVChart = new wijmo.chart.hierarchical.Sunburst('#groupCVChart', { binding: 'value', itemsSource: getGroupCVData(), dataLabel: { position: 'Center', content: '{name}' } });

#### Result (live):

## Basic Features

The Sunburst chart control has five basic properties that allow you to customize its layout and appearance:

- innerRadius: Specifies the control's inner radius to support donut charts.
- offset: Specifies the offset of the sunburst slices from the center of the control.
- startAngle: Starting at the nine o'clock position, specifies the angle to start drawing sunburst slices.
- palette: Specifies an array of default colors to be used when rendering sunburst slices.
- reversed: Determines whether the control should draw sunburst slices clockwise (false) or counterclockwise (true).

The example below allows you to see what happens when you change these properties. Also, clicking on a sunburst slice will display a tooltip for the data point.

HTML
<div id="basicChart"></div> <div class="form-horizontal"> <div class="form-group"> <label class="col-md-3 control-label">Inner Radius</label> <div class="col-md-9"> <input id="basicInnerRadius" type="text" /> </div> </div> <div class="form-group"> <label class="col-md-3 control-label">Offset</label> <div class="col-md-9"> <input id="basicOffset" type="text" /> </div> </div> <div class="form-group"> <label class="col-md-3 control-label">Start Angle</label> <div class="col-md-9"> <input id="basicStartAngle" type="text" /> </div> </div> <div class="form-group"> <div class="col-md-offset-3 col-md-9"> <div id="basicPalette"></div> </div> </div> <div class="form-group"> <div class="col-md-offset-3 col-md-9"> <div class="checkbox"> <label> <input id="basicReversed" type="checkbox" /> Reversed </label> </div> </div> </div> </div>
JS
var basicChart = new wijmo.chart.hierarchical.Sunburst('#basicChart', { binding: 'value', bindingName: 'year, quarter, month', childItemsPath: 'items', itemsSource: getHierarchicalData(), dataLabel: { position: 'Center', content: '{name}' } }); // change the chart properties var innerRadius = new wijmo.input.InputNumber('#basicInnerRadius', { min: 0, max: 1, step: 0.1, format: 'n1', valueChanged: function (s, e) { if (s.value >= s.min && s.value <= s.max) { basicChart.innerRadius = s.value; } } }); var offset = new wijmo.input.InputNumber('#basicOffset', { min: 0, max: 1, step: 0.1, format: 'n1', valueChanged: function (s, e) { if (s.value >= s.min && s.value <= s.max) { basicChart.offset = s.value; } } }); var startAngle = new wijmo.input.InputNumber('#basicStartAngle', { min: -360, max: 360, step: 45, valueChanged: function (s) { if (s.value >= s.min && s.value <= s.max) { basicChart.startAngle = s.value; } } }); var palettes = new wijmo.input.Menu('#basicPalette', { itemsSource: 'standard,cocoa,coral,dark,highcontrast,light,midnight,minimal,modern,organic,slate'.split(','), textChanged: function (s, e) { if (s.selectedValue) { basicChart.palette = wijmo.chart.Palettes[s.text]; updateMenuHeader(s, 'Palette'); } } }); updateMenuHeader(palettes, 'Palette'); document.getElementById('basicReversed').addEventListener('click', function (e) { basicChart.reversed = e.target.checked; });

#### Result (live):

Inner Radius
Offset
Start Angle
Reversed

## Legend and Titles

The legend properties can be used to customize the appearance of the chart's legend. You can also use the header and footer properties to add titles to the Sunburst chart control.

The following example allows you to change the Sunburst's legend.position, header, and footer properties in real-time.

HTML
<div id="ltChart"></div> <div class="form-horizontal"> <div class="form-group"> <label class="col-md-3 control-label">Header</label> <div class="col-md-9"> <input id="ltHeader" type="text" class="form-control" placeholder="Specify the Sunburst's header" /> </div> </div> <div class="form-group"> <label class="col-md-3 control-label">Footer</label> <div class="col-md-9"> <input id="ltFooter" type="text" class="form-control" placeholder="Specify the Sunburst's footer" /> </div> </div> <div class="form-group"> <div class="col-md-offset-3 col-md-9"> <select id="ltLegPos"> <option value="None">None</option> <option value="Left">Left</option> <option value="Top">Top</option> <option value="Right">Right</option> <option value="Bottom">Bottom</option> </select> </div> </div> </div>
JS
var ltChart = new wijmo.chart.hierarchical.Sunburst('#ltChart', { binding: 'value', bindingName: ['year', 'quarter', 'month'], itemsSource: getData(), header: 'Sales', footer: 'GrapeCity, inc.', }); // change chart properties var header = document.getElementById('ltHeader'); header.value = ltChart.header; header.addEventListener('input', function (e) { ltChart.header = e.target.value; }); var footer = document.getElementById('ltFooter'); footer.value = ltChart.footer; footer.addEventListener('input', function (e) { ltChart.footer = e.target.value; }); var ltLegPos = new wijmo.input.Menu('#ltLegPos', { itemClicked: function (s, e) { ltChart.legend.position = s.selectedValue; updateMenuHeader(s, 'Legend Position'); }, selectedValue: 'Right' }); updateMenuHeader(ltLegPos, 'Legend Position');

#### Result (live):

Header
Footer

## Selection

The Sunburst chart control allows you to select data points by clicking or touching a sunburst slice. Use the selectionMode property to specify whether you want to allow selection by data point or no selection at all (default).

Setting the selctionMode property to Point causes the Sunburst to update the selection property when the user clicks on a sunburst slice, and to apply the "wj-state-selected" class to the selected element. Setting the Sunburst's selectionMode property to Series or None will disable selections within the control.

The Sunburst chart offers three additional properties to customize the selection:

- selectedItemOffset: Specifies the offset of the selected sunburst slice from the center of the control.
- selectedItemPosition: Specifies the position of the selected sunburst slice. The available options are Top, Bottom, Left, Right, and None (default).
- isAnimated: Determines whether or not to animate the selection.

HTML
<div id="selChart"></div> <div class="form-horizontal"> <div class="form-group"> <label class="col-md-3 control-label">Selected Item Offset</label> <div class="col-md-9"> <input id="selItemOffset" type="text" /> </div> </div> <div class="form-group"> <div class="col-md-offset-3 col-md-9"> <select id="selItemPos"> <option value="None">None</option> <option value="Left">Left</option> <option value="Top">Top</option> <option value="Right">Right</option> <option value="Bottom">Bottom</option> </select> </div> </div> <div class="form-group"> <div class="col-md-offset-3 col-md-9"> <div class="checkbox"> <label> <input id="selAnimated" type="checkbox" checked="checked"> Animated </label> </div> </div> </div> </div>
JS
var selChart = new wijmo.chart.hierarchical.Sunburst('#selChart', { binding: 'value', bindingName: ['year', 'quarter', 'month'], itemsSource: getData(), isAnimated: true, selectionMode: 'Point', selectedItemPosition: 'Top' }); // change chart properties var selItemOffset = new wijmo.input.InputNumber('#selItemOffset', { min: 0, max: 0.5, step: 0.1, format: 'n1', valueChanged: function (s) { if (s.value >= s.min && s.value <= s.max) { selChart.selectedItemOffset = s.value; } } }); var selItemPos = new wijmo.input.Menu('#selItemPos', { itemClicked: function (s, e) { selChart.selectedItemPosition = s.selectedValue; updateMenuHeader(s, 'Selected Item Position'); }, selectedValue: 'Top' }); updateMenuHeader(selItemPos, 'Selected Item Position'); document.getElementById('selAnimated').addEventListener('click', function (e) { selChart.isAnimated = e.target.checked; });

#### Result (live):

Selected Item Offset
Animated

## Theming

The appearance of the Sunburst chart control is largely defined in CSS. In addition to a default theme, we include several professionally designed themes that customize the appearance of all Wijmo controls to achieve a consistent and attractive look.

You can customize the appearance of the Sunburst chart control using CSS. To do this, copy the CSS rules from the default theme to a new CSS file and modify the rules as needed.

In this example, we added the "custom-sunburst-chart" CSS class to the control and defined some CSS rules to change the fill, font family, and font weight of the header and fill color of the slices.

HTML
<div id="themeChart" class="custom-sunburst-chart"></div>
JS
var themeChart = new wijmo.chart.hierarchical.Sunburst('#themeChart', { itemsSource: getData(), header: 'Bullseye(target)', binding: 'value', bindingName: 'name', childItemsPath: 'items', legend: { position: 'None' }, tooltip: { content: '' } });
CSS
/* custom Sunburst theme */ .custom-sunburst-chart.wj-sunburst .wj-header .wj-title { fill: #666; font-family: 'Courier New', Courier, monospace; font-weight: bold; } .custom-sunburst-chart.wj-sunburst ellipse, .custom-sunburst-chart.wj-sunburst path { stroke-width: 0; } .custom-sunburst-chart.wj-sunburst ellipse { fill: yellow; } .custom-sunburst-chart.wj-sunburst .slice-level2 > path { fill: red; } .custom-sunburst-chart.wj-sunburst .slice-level3 > path { fill: blue; } .custom-sunburst-chart.wj-sunburst .slice-level4 > path { fill: black; } .custom-sunburst-chart.wj-sunburst .slice-level5 > path { fill: white; stroke-width: 2; stroke: black; }

#### Result (live):