I have a horizontal single bar chart showing percentage inside of an ag-grid row, I would like to add a line at a certain percentage to show a target. I am using the annotations plugin which is registered. I have tried several different versions of the annotation options but cannot get anything to show on the chart. Any help would be greatly appreciated :)
const options = {
indexAxis: 'y' as const,
responsive: true,
scales: {
xAxis: {
max: 100,
min: 0,
display: false,
},
yAxis: {
display: false,
},
},
plugin: {
annotation: {
annotations: [
{
type: 'line' as const,
mode: 'vertical',
scaleID: 'x',
value: 80,
borderColor: 'black',
borderWidth: 2,
},
],
},
},
};
const dataset = {
labels: ['In-session utilisation (%)'],
datasets: [
{
id: 1,
label: '',
data: [theatreUtilisation],
backgroundColor: theme.color.accentB,
},
],
};
return (
<>
<Bar data={dataset} options={options} />
</>
);
If I'm not wrong, there are some errors in chart configuration.
pluginis not the correct node name but ispluginsxscale which is not defined, because you definedxAxes.Furthermore it seems you are using CHART.JS 3 but the annotation plugin version 0.x. From plugin README:
For Chart.js 3.0.0 to 3.6.2 support, use version 1.4.0 of this plugin For Chart.js 2.4.0 to 2.9.x support, use version 0.5.7 of this plugin
I have attached here a sample, fixing the config, using CHART.JS 3.9.1 and ANNOTATION 2.0.1: