Accessible line chart

author(s): Torstein Hønsi

by oysteinmoseng

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/accessibility.js"></script>

<input type="text" value="Click to focus">
<figure class="highcharts-figure">
    <div id="container"></div>
    <p class="highcharts-description">Illustrating legend above chart. Menu button is first in tab order, legend is second, data points are third.</p>
</figure>
<input type="text" value="After chart">

CSS

#container {
    height: 420px; 
}

.highcharts-figure, .highcharts-data-table table {
    min-width: 360px; 
    max-width: 820px;
    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

var colors = Highcharts.getOptions().colors;

Highcharts.chart('container', {
    chart: {
        type: 'spline'
    },

	accessibility: {
    	keyboardNavigation: {
        	order: ['chartMenu', 'legend', 'series']
        }
    },

    legend: {
        symbolWidth: 40,
        verticalAlign: 'top'
    },

    title: {
        text: 'Legend above chart'
    },

    series: [
        { data: [34.8, 43.0, 51.2, 41.4, 64.9, 72.4] },
        { data: [69.6, 63.7, 63.9, 43.7, 66.0, 61.7] }
    ]
});