I'm creating a line chart using chartjs (v3) (and react-chartjs to integrate) and I'm having some bad times to customize the line to start at the middle of the first column (and also finishes at the middle of the last column) because the first column will always be in a zero Y position so that makes the line start at the very left. So I need to figure out how to make the lines to mark in the middle of the column instead of the border.
This is the result I have:
And I need something like this:
My config:
<Line
data={data}
height={440}
width={480}
options={{
...options,
scales: {
x: {
grid: {
color(context) {
if (context.tick.value === 0) return '#B3B3B3';
return '#E6E6E6';
},
tickWidth: 0,
lineWidth: 1,
},
border: {
dash(context) {
if (context.tick.value === 0) return [0];
return [5, 5];
},
width: 0,
},
ticks: {
display: false,
},
},
y: {
grid: {
color(context) {
if ([0, 30, 70].includes(context.tick.value)) {
return '#B3B3B3';
}
return '#E6E6E6';
},
lineWidth(context) {
if ([30, 70].includes(context.tick.value)) {
return 2;
}
return 1;
},
tickWidth: 0,
},
border: {
dash(context) {
if (context.tick.value === 0) return [0];
return [5, 5];
},
width: 1,
},
min: 0,
max: 100,
ticks: {
font: {
weight: 'bold',
size: 10,
family: 'Open Sans',
},
color: '#000000',
},
},
},
animation: false,
plugins: {
legend: {
display: false,
},
tooltip: {
enabled: false,
},
},
}}
/>
scales.x.offset: true
option, see the docsoffset: true
for thex.grid
configuration too, see the docs. It would be useful to simplify your code and extract something easily runnable that we can work with. Your issue doesn't seem to have anything to do with react, nor with multiple datasets, so you can make something on the lines of this fiddle.