Chart.js plugin for Chart2Music. Turns chart.js charts into music so the blind can hear data.
npm install chartjs-plugin-chart2musicjs
import {Chart} from "chart.js/auto";
import chartjs2music from "chartjs-plugin-chart2music";
Chart.register(chartjs2music);
`
That will register the plugin globally. Alternatively, if you only want to enable for a given chart, you can do this:
`js
import {Chart} from "chart.js/auto";
import chartjs2music from "chartjs-plugin-chart2music";
new Chart(canvasElement, {
type: "bar",
data: {
datasets: [{
data: [1,4,2,8]
}]
},
plugins: [chartjs2music]
})
`
Available options
The following plugin options are available:
* errorCallback - A callback that will return errors if any arise while the plugin works.
* cc - the equivalent of the chart2music option cc
* audioEngine - the equivalent of the chart2music option audioEngine
* axes - the equivalent of the chart2music option axes
* lang - the language your user speaks. The available languages that Chart2Music supports are: "en", "de", "es", "fr", "it". The default is "en". If you would like to add translations for another language, Chart2Music is open to PRs.
Here's an example for providing options:
`js
import {Chart} from "chart.js/auto";
import chartjs2music from "chartjs-plugin-chart2music";
new Chart(canvasElement, {
type: "bar",
data: {
datasets: [{
data: [1,4,2,8]
}]
},
options: {
plugins: {
chartjs2music: {
// All errors should be logged as errors
errorCallback: console.error,
// Here's a div I made to be the CC
cc: myDiv,
// The Y values should all be money
axes: {
y: {
format: (value) => "$" + value
}
}
}
}
},
plugins: [chartjs2music]
});
`
If you are using TypeScript, replace the first 4 lines with this:
`ts
import {Chart, type ChartTypeRegistry} from "chart.js/auto";
import chartjs2music from "chartjs-plugin-chart2music";
new Chart(canvasElement, {
type: "bar" as keyof ChartTypeRegistry,
`
Supported features
This plugin is currently in beta, so not all of the chart.js features are currently supported.
A quick list of chart.js features we currently support includes:
* Chart types: bar, doughnut, line, pie, polar, radar, scatter, and combinations therein.
* Boxplots using the @sgratzl/chartjs-chart-boxplot plugin (only support boxplots when there are no other chart types present)
* Wordclouds using the chartjs-chart-wordcloud plugin
* Axes options: title, min, max, type="linear", type="logarithmic".
* Chart title
* Most data structures (not including parsing or non-standard axes identifiers)
* Dataset visibility (when you show/hide a category from the legend)
Note that visual-specific chart features are ignored. This includes things like color, padding, line thickness, etc.
Things we plan to support in the future:
* Interactions and updates
* Other chart.js plugins
* Complex parsing` options for data