Accessibility plugin for Chartist.js
This plugin generates a visually hidden table to make your Chartist charts accessible.
Please visit http://gionkunz.github.io/chartist-js/plugins.html for more information.
Available options and their defaults
var defaultOptions = {
caption: 'A graphical chart',
seriesHeader: 'Series name',
valueTransform: Chartist.noop,
summary: undefined,
class: undefined,
elementId: function () {
return 'ct-accessibility-table-' + (+new Date());
},
visuallyHiddenStyles: 'position:absolute;left:-10000px;top:auto;width:1px;height:1px;overflow:hidden;'
};
Sample usage for a line chart
var chart = new Chartist.Line('.ct-chart', {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
series: [
{name: 'Income', data: [20000, 30000, 35000, 32000, 40000, 42000, 50000, 62000, 80000, 94000, 100000, 120000]},
{name: 'Expenses', data: [10000, 15000, 12000, 14000, 20000, 23000, 22000, 24000, 21000, 18000, 30000, 32000]}
]
}, {
plugins: [
Chartist.plugins.ctAccessibility({
caption: 'Fiscal year 2015',
seriesHeader: 'business numbers',
summary: 'A graphic that shows the business numbers of the fiscal year 2015',
valueTransform: function(value) {
return value + ' dollar';
}
})
]
});
Sample usage for a pie chart
var chart = new Chartist.Pie('.ct-chart', {
labels: ['Carbohydrates', 'Protein', 'Fat'],
series: [24, 8, 2]
}, {
plugins: [
Chartist.plugins.ctAccessibility({
caption: 'Nutrients of a banana',
summary: 'A graphic that shows the nutrients of a banana',
valueTransform: function(value) {
var total = chart.data.series.reduce(function(prev, current) {
return prev + current;
}, 0);
return Math.round(value / total * 100) + '%' + ' with ' + value + ' grams';
}
})
]
});
Generated accessibility table for the above example
<div style="position:absolute;left:-10000px;top:auto;width:1px;height:1px;overflow:hidden;" id="ct-accessibility-table-1425311150915">
<table summary="A graphic that shows the nutrients of a banana">
<caption>Nutrients of a banana</caption>
<tbody>
<tr>
<th scope="col" role="columnheader">Carbohydrates</th>
<th scope="col" role="columnheader">Protein</th>
<th scope="col" role="columnheader">Fat</th>
</tr>
<tr>
<td>71% with 24 grams</td>
<td>24% with 8 grams</td>
<td>6% with 2 grams</td>
</tr>
</tbody>
</table>
</div>