I have a bar chart using react-chartjs-2
with a bunch of stacked bars, and I want all (incl. the middle ones) have rounded top corners. This is relatively easily done, but the middle ones leave an ugly white gap. What I would like is to fill these gaps with the colour of the next one.
Is this possible? I can't find any option for this (only backgroundColor
and borderColor
).
This is built from the code:
import React from 'react';
import { Bar } from 'react-chartjs-2';
export const barOptions = {
responsive: true,
scales: {
x: {
stacked: true,
},
y: {
stacked: true,
},
},
plugins: {
legend: {
position: 'top' as const,
},
},
maintainAspectRatio: false,
};
const MyBarExample = () => {
const [barLabels, setBarLabels] = React.useState<string[]>([]);
const [dataSet1, setdataSet1] = React.useState<(getDataSet1 | null)[] | null>(null);
const [dataSet2, setdataSet2] = React.useState<(getDataSet2 | null)[] | null>(null);
//
// Get data
// ...
const barData = {
labels: barLabels,
datasets: [
{
label: 'Type 1 A',
data: dataSet1?.map((lng) => lng?.A || '') || [],
backgroundColor: '#7482FF',
borderColor: '#7482FF',
stack: 'Stack 0',
borderRadius: {
topLeft: 12,
topRight: 12,
},
},
{
label: 'Type 1 B',
data: dataSet1?.map((lng) => lng?.B || '') || [],
backgroundColor: 'rgba(116,130,255,0.7)',
borderColor: 'rgba(116,130,255,0.7)',
stack: 'Stack 0',
borderRadius: {
topLeft: 12,
topRight: 12,
},
},
{
label: 'Type 1 C',
data: dataSet1?.map((lng) => lng?.C || '') || [],
backgroundColor: 'rgba(116,130,255,0.15)',
borderColor: 'rgba(116,130,255,0.15)',
stack: 'Stack 0',
borderRadius: {
topLeft: 12,
topRight: 12,
},
},
{
label: 'Type 2 A',
data: dataSet2?.map((lng) => lng?.A || '') || [],
backgroundColor: '#FF7D45',
borderColor: '#FF7D45',
stack: 'Stack 1',
borderRadius: {
topLeft: 12,
topRight: 12,
},
},
{
label: 'Type 2 B',
data: dataSet2?.map((lng) => lng?.B || '') || [],
backgroundColor: 'rgba(255,125,69,0.7)',
borderColor: 'rgba(255,125,69,0.7)',
stack: 'Stack 1',
borderRadius: {
topLeft: 12,
topRight: 12,
},
},
{
label: 'Type 2 C',
data: dataSet2?.map((lng) => lng?.C || '') || [],
backgroundColor: 'rgba(255,125,69,0.15)',
stack: 'Stack 1',
borderRadius: {
topLeft: 12,
topRight: 12,
},
},
],
};
return (
<Bar width="100%" height="100%" options={barOptions} data={barData} />
);
};
export default MyBarExample;