Sunburst

author(s): Torstein Hønsi

by koh_edwin

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>
<script src="https://code.highcharts.com/themes/adaptive.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

* {
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        Helvetica,
        Arial,
        "Apple Color Emoji",
        "Segoe UI Emoji",
        "Segoe UI Symbol",
        sans-serif;
}

.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 var(--highcharts-neutral-color-10, #e6e6e6);
    margin: 10px auto;
    text-align: center;
    width: 100%;
    max-width: 500px;
}

.highcharts-data-table caption {
    padding: 1em 0;
    font-size: 1.2em;
    color: var(--highcharts-neutral-color-60, #666);
}

.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 tbody tr:nth-child(even) {
    background: var(--highcharts-neutral-color-3, #f7f7f7);
}

.highcharts-description {
    margin: 0.3rem 10px;
}

JavaScript

const createChart = data => Highcharts.chart('container', {

    chart: {
        height: '100%'
    },

    // Let the center circle be white transparent
    colors: ['#ffffff01'].concat(Highcharts.getOptions().colors),

    
    series: [{
        type: 'sunburst',
        data: data,
        name: 'Root',
        allowTraversingTree: true,
        borderRadius: 3,
        cursor: 'pointer',
        dataLabels: {
            format: '{point.name}',
            filter: {
                property: 'innerArcLength',
                operator: '>',
                value: 16
            }
        },
        levels: [{
            level: 1,
            levelIsConstant: false,
            dataLabels: {
                filter: {
                    property: 'outerArcLength',
                    operator: '>',
                    value: 64
                }
            }
        }, {
            level: 2,
            colorByPoint: true
        },
        {
            level: 3,
            colorVariation: {
                key: 'brightness',
                to: -1
            }
        }, {
            level: 4,
            colorVariation: {
                key: 'brightness',
                to: 1
            }
        }]

    }],
});

// Define the data
const data = [{
    id: '0.0',
    parent: '',
    name: 'Expertise'
}, {
    id: '1.3',
    parent: '0.0',
    name: 'Qlik Sense'
}, {
    id: '1.1',
    parent: '0.0',
    name: 'javascript'
}, {
    id: '1.2',
    parent: '0.0',
    name: 'SQL'
}, {
    id: '1.4',
    parent: '0.0',
    name: 'Europe'
}, 


{
    id: '2.1',
    parent: '1.1',
    name: 'Eastern Africa'
},

{
    id: '3.1',
    parent: '2.1',
    name: 'Ethiopia',
    value: 126527060
}, {
    id: '3.2',
    parent: '2.1',
    name: 'Tanzania',
    value: 67438106
}, {
    id: '3.3',
    parent: '2.1',
    name: 'Kenya',
    value: 55100587
}, {
   ...