Highcharts Demo

author(s): Marita Vindedal

by maritavindedal

HTML

<script src="https://code.highcharts.com/highcharts.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">The following chart demonstrates some Accessibility features of Highcharts, including use of the <code>rangeDescription</code> and <code>axis.description</code> options.
    The <code>yAxis.accessibility.description</code> in this demo is summarizing that the yAxis will show the total number of steps per person per day, since the column chart is stacked. 
    The <code>yAxis.accessibility.rangeDescription</code> is showing the range values of the columns.</p>
</figure>

CSS

#container {
    max-width: 800px;
    height: 400px;
    margin: 1em auto;
}

caption {
    padding-bottom: 5px;
    font-family: Verdana, sans-serif;
    font-size: 14pt;
    font-weight: bold;
    color: #555;
}

table {
    font-family: Verdana, sans-serif;
    font-size: 12pt;
    color: #555;
    border-collapse: collapse;
    border: 3px solid #ccc;
    margin: 2px auto;
}

tr {
    border-bottom: 2px solid #eee;
}

th {
    border-left: 2px solid #eee;
    border-right: 2px solid #eee;
    padding: 12px 15px;
    border-collapse: collapse;
}

th[scope="col"] {
    background-color: #ffe;
}

th[scope="row"] {
    background-color: #f0fcff;
    text-align: left;
}

td {
    border-left: 2px solid #eee;
    border-right: 2px solid #eee;
    padding: 12px 15px;
    border-collapse: collapse;
}

JavaScript

Highcharts.Templating.helpers.sum = function () {
    return this.series.points.reduce((sum, point) => sum + point.y, 0);
};

Highcharts.Templating.helpers.max = function () {
    return this.series.points.reduce((max, point) => Math.max(max, point.y), 0);
};

// Custom helper to log the context
Highcharts.Templating.helpers.log = function () {
    console.log(this.chart.yAxis[0].dataMin);
};

Highcharts.chart('container', {
    chart: {
        type: 'column'
    },
    title: {
        text: 'Daily Steps Count'
    },
    xAxis: {
        categories: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
        accessibility: {
            description: 'Day of the week'
        }
    },
    yAxis: {
        title: {
            text: 'Steps'
        },
        accessibility: {
            description: 'Daily steps in total for all three persons',
            rangeDescription: '{log}'
        },
        stackLabels: {
            enabled: true
        }
    },
    tooltip: {
        valueSuffix: ' steps'
    },
    plotOptions: {
        series: {
            stacking: 'normal'
        }
    },
    series: [{
        name: 'Emma',
        data: [9438, 10439, 11023, 13204, 10392, 9201, 12039],
        color: '#009AFA',
        accessibility: {
            descriptionFormat: '{series.name} walked the most in total ' +
            'during the week with {sum} steps.'
        }
    }, {
        name: 'John',
        data: [10200, 6243, 9472, 6311, 7901, 11320, 8032],
        color: '#3A3691'
    }, {
        name: 'Alex',
        data: [9029, 5532, 7632, 10320, 6210, 13209, 3052],
        color: '#00A855',
        accessibility: {
            descriptionFormat: '{series.name} had the highest number of ' +
                'steps in a day during the week on Saturday. ' +
                'He walked {max} steps that day.'
        }
    }]
});