chart-access
Add an accessible, auto-generated fallback to a Chart.js chart.
Install
npm install chart-access
How to use
;
or
Using chart-access with a script tag adds a global variable chartaccess
to the browser window with the addFallback
function.
Add fallback text
Use addFallback
to add auto-generated fallback text to the canvas for a chart created with Chart.js.
chartaccess;
Example
; // config for chartlet chartConfig = type: 'line' data: data options: title: text: 'Iced Coffees Consumed Each Month of the Year' display: true // create Chart.js chartlet canvas = document;let titledChart = canvas chartConfig; // add auto-generated fallback text to chart canvaschartaccess;
Now the canvas element for your chart will provide screen reader users with basic information about the chart:
Line chart titled, 'Iced Coffees Consumed Each Month of the Year'.
If your chart does not contain title text, the fallback text will be:
Untitled line chart.