I'm trying to add/draw arrows to the axis of my charts. (So they can look a bit more like that)
I've tried to look into the doc, but I didn't find any options concerning in the scales part. I tried to do it by using the annotation plugins, but it fall short as on a bar scheme the arrow seems limited on the x axis, and I didn't find a way for it to overflow.
I found a person having a similar problem, but it is on an older version of the library
Do I need to do a custom scales class ?
Here is my current test implementation
const data = {
labels: ["Label1","Label2","Label3","Label4"],
datasets: [{
label: 'First Dataset',
data: [1349,282,274,173],
backgroundColor: ["blue"],
}]
};
const annotation1 = {
type: 'line',
borderColor: "red",
borderWidth: 3,
arrowHeads: {
end: {
enabled: true,
// borderColor: 'green'
}
},
scaleID: 'y',
value: 0
};
const annotation2 = {
type: 'line',
borderColor: "red",
borderWidth: 3,
arrowHeads: {
end: {
enabled: true,
}
},
xMax: 0,
xMin: 0,
xScaleID: 'x',
yMax: 1500,
yMin: 0,
yScaleID: 'y'
};
const ctx= document.getElementById('myChart').getContext('2d');
const myChart = new Chart(ctx, {
type: 'bar',
data: data,
options: {
padding: 10,
scales: {
x: {
grid: {
display: false,
borderColor: "red",
borderWidth: 3,
z:4,
},
grace: '10%'
},
y: {
grid: {
display: false,
borderColor: "red",
borderWidth: 3,
padding: 100,
},
ticks: {
display: false,
padding: 100,
},
grace: '10%',
padding: 100,
},
},
plugins: {
legend: {
display: false,
},
tooltip: {
enabled: false,
},
datalabels: {
labels: {
value: {
align: 'end',
anchor: 'end',
color: "black",
formatter: function (value, ctx) {
return value;
},
},
}
},
annotation: {
drawTime: 'beforeDraw',
annotations: {
annotation1,
annotation2
}
},
}
},
plugins: [ChartDataLabels],
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.7.1/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2.0.0/dist/chartjs-plugin-datalabels.min.js"></script></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-annotation/1.4.0/chartjs-plugin-annotation.min.js"></script>
<canvas id="myChart" ></canvas>