/*
This is an advanced demo showing how to create custom accessibility
functionality for a chart. This allows us to add elements to the
keyboard navigation, as well as perform accessibility related tasks
whenever updates are made to the chart.
*/
// Create a basic chart
const chart = Highcharts.chart('container', {
xAxis: {
categories: [
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
'Oct', 'Nov', 'Dec'
]
},
series: [{
data: [
29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6,
148.5, 216.4, 194.1, 95.6, 54.4
]
}]
});
// Add a custom button. We add this to the chart, and store it in our own
// namespace to avoid conflicts with other chart properties.
chart.myNamespace = {};
chart.myNamespace.myButton = chart.renderer.button(
'Custom button', 60, 10, function () {
alert('Custom Button Pressed');
}
).add();
// Create the custom accessibility component for the chart. This class inherits
// from the AccessibilityComponent class.
const CustomComponent = function (chart) {
this.initBase(chart);
};
CustomComponent.prototype = new Highcharts.AccessibilityComponent();
Highcharts.extend(CustomComponent.prototype, {
// Perform tasks to be done when the chart is updated
onChartUpdate: function () {
// Get our button if it exists, and set attributes on it
const namespace = this.chart.myNamespace || {};
if (namespace.myButton) {
namespace.myButton.attr({
role: 'button',
tabindex: -1
});
Highcharts.A11yChartUtilities.unhideChartElementFromAT(
this.chart, namespace.myButton.element
);
}
},
// Define keyboard navigation for this component
getKeyboardNavigation: function () {
const keys = this.keyCodes,
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.