Country > Customer Class > Channel

by linhpham84

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),

    title: {
        text: ' Country > Customer Class > Channel'
    },

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

    }],

    tooltip: {
        headerFormat: '',
        pointFormat: '<b>{point.label} {point.name}</b>:<b> ' + 
            '{point.value}</b>'
    }
});

// Define the data
const data = [
    {
        id: '1',
        parent: '',
        name: '    '
    },
    {
        id: 'France',
        parent: '1',
        name: 'France',
        label: 'Country'
    },
    {
        id: 'France.A',
        parent: 'France',
        name: 'A',
        label: 'Customer Class'
    },
    {
        id: 'France.B',
        parent: 'France',
        name: 'B',
        label: 'Customer Class'
    },
    {
        id: 'France.C',
        parent: 'France',
        name: 'C',
        label: 'Customer Class'
    },
    {
        id: 'Germany',
        parent: '1',
        name: 'Germany',
        label: 'Country'
    },
    {
        id: 'Germany.A',
        parent: 'Germany',
        name: 'A',
        label: 'Customer...