Sunburst

author(s): Torstein Hønsi

by wcreedh

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/sunburst.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>

<figure class="highcharts-figure">
    <div id="container"></div>
    <p class="highcharts-description">
        Sunburst charts are used to visualize hierarchical data in a
        circular shape. The inner elements are parent nodes, with
        child nodes distributed on the outer rings. Click on a parent
        node to drill down and inspect the tree in more detail.
    </p>
</figure>

CSS

.highcharts-figure, .highcharts-data-table table {
    min-width: 320px; 
    max-width: 800px;
    margin: 1em auto;
}

.highcharts-data-table table {
	font-family: Verdana, sans-serif;
	border-collapse: collapse;
	border: 1px solid #EBEBEB;
	margin: 10px auto;
	text-align: center;
	width: 100%;
	max-width: 500px;
}
.highcharts-data-table caption {
    padding: 1em 0;
    font-size: 1.2em;
    color: #555;
}
.highcharts-data-table th {
	font-weight: 600;
    padding: 0.5em;
}
.highcharts-data-table td, .highcharts-data-table th, .highcharts-data-table caption {
    padding: 0.5em;
}
.highcharts-data-table thead tr, .highcharts-data-table tr:nth-child(even) {
    background: #f8f8f8;
}
.highcharts-data-table tr:hover {
    background: #f1f7ff;
}

JavaScript

function formatNumber(num) {
  return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
}
var data = [{
  id: '0.0',
  parent: '',
  name: ' '
}, {
  id: '1.3',
  parent: '0.0',
  name: 'For',
  color: 'blue'
}, {
  id: '1.1',
  parent: '0.0',
  name: 'Expense',
  color: 'red'
}, {
  id: '1.2',
  parent: '0.0',
  name: 'Revenue',
  color: 'green'

}, {
  id: '3.1',
  parent: '2.1',
  name: 'SMT embankment',
  value: 84501.58
}, {
  id: '3.2',
  parent: '2.1',
  name: 'Shearwater Flyer bridge',
  value: 676.97
}, {
  id: '3.3',
  parent: '2.1',
  name: 'SMT parking lot study',
  value: 0
}, {
  id: '3.4',
  parent: '2.1',
  name: 'CHHP Vault Toilet',
  value: 0
}, {
  id: '3.5',
  parent: '2.1',
  name: 'Flyer Surface and side recap',
  value: 0
}, {
  id: '3.6',
  parent: '2.2',
  name: 'Engagement/ AGM / volunteer events',
  value: 6750.95
}, {
  id: '3.7',
  parent: '2.2',
  name: 'CHHP - Trails maintenance and  mowing',
  value: 6506.6
}, {
  id: '3.8',
  parent: '2.2',
  name: 'Salt Marsh Trail Maintenance ',
  value: 4788.95
}, {
  id: '3.9',
  parent: '2.2',
  name: 'Salt Marsh Trail Amenities ',
  value: 4484.13
}, {
  id: '3.10',
  parent: '2.2',
  name: 'Organizational  expenses',
  value: 3741
}, {
  id: '3.11',
  parent: '2.2',
  name: 'Routine material',
  value: 2376.33
}, {
  id: '3.12',
  parent: '2.2',
  name: 'Dog Bags SMT and SFT',
  value: 2273.21
}, {
  id: '3.13',
  parent: '2.2',
  name: 'CHHPAmenities maintenance',
  value: 2215.12
}, {
  id: '3.14',
  parent: '2.2',
  name: 'Shearwater Flyer trail maintenance',
  value: 1310.5
}, {
  id: '3.15',
  parent: '2.2',
  name: 'Routine equipment',
  value: 1272.09
}, {
  id: '3.16',
  parent: '2.2',
  name: 'Heritage Trail Amenities maintenance ',
  value: 1256
}, {
  id: '3.17',
  parent: '2.2',
  name: 'Spring Cleaning',
  value: 900
}, {
  id: '3.18',
  parent: '2.2',
  name: 'Shearwater Flyer amenities',
  value: 730
}, {
  id: '3.19',
  parent: '2.2',
  name: 'Buildings (CHPTA...