I am trying to make a an area chart that has x axis labels displayed above the actual axis itself. Here's an example:
I have the axis labels, but I cannot find a way to move them just above the X axis
Chart.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Filler)
const options = {
layout: { padding: { top: 50 } },
responsive: true,
elements: {
line: {
tension: 0.4, // makes the line smoother
},
point: {
radius: 0,
},
},
scales: {
x: {
grid: {
display: false, // hides lines in background
drawBorder: false,
},
},
y: {
beginAtZero: true,
grid: {
display: false, // hides lines in background
drawBorder: false,
},
ticks: {
display: false,
},
},
},
}
const chartData = {
labels: ['JAN', 'FEB', 'MAR', ...],
datasets: [
{
data: [12, 79, 56, ...],
borderWidth: 5,
},
],
}
export const Graph = () => {
return (
<div>
....
<Line plugins={plugins} options={options} data={chartData} />
</div>
)
}
I need it to be responsive, being able to change the time window that is graphed. I tried to do an afterDraw() function however that isn't ideal given the need to responsive.
After some digging, I was able to find this solution:
const options: {
...
scales:{ x: position: { y: 20 } }. <------------------ Answer here
}