DEV Community

sarra
sarra

Posted on

Double Stacked Column Chart / Combination of Stacked and Column Chart

i want to create chart like this on :

Image description
but the stacked aren't straight :

Image description
this is my code :
import React from 'react';
import { Bar } from 'react-chartjs-2';
import { Chart as ChartJS, BarElement, CategoryScale, Tooltip, Legend, LinearScale } from 'chart.js';

ChartJS.register(BarElement, CategoryScale, LinearScale, Tooltip, Legend);

const StackedBar = () => {
const categories = [
'Abandoned Baskets',
'Chat',
'Contest',
'Fixed Net (5G GigaBox)',
'Fixed Net (Cable)',
'Fixed Net (Fiber)',
'MNP/Churn',
'Up-Sell Mobile (Prepaid)',
'X-Sell MBB',
'X-Sell Mobile (Fiber only)',
];

const callVolumeData = categories.map((category, index) => ({
label: ${category} - Call Volume,
data: [10000], // Replace with actual call volume data
backgroundColor: rgba(64, 169, 252, ${0.1 + (index + 1) * 0.1}), // Shades of blue
yAxisID: 'y1',
}));

const engagementData = categories.map((category, index) => ({
label: ${category} - Engagement KPI,
data: [1000],
backgroundColor: rgba(37, 56, 88, ${0.1 + (index + 1) * 0.1}), // Shades of blue
yAxisID: 'y2',
borderWidth: 1,
circular: true

}));

const data = {
labels: ['2023/01', '2023/02', '2023/04', '2023/05', '2023/06', '2023/07', '2023/08'],
datasets: [...callVolumeData, ...engagementData],
};

const options = {
plugins: {
legend:{
display:true,
position: 'left',
labels: {
usePointStyle: true,
boxWidth: 6
}
},
title: {
display: true,
text: 'Chart.js Bar Chart - Side by Side',
},

},
scales: {
  x: {
    barPercentage: 3  ,
    categoryPercentage: 0.6
  },
  y1: {
    position: 'left',
    title: {
      display: true,
      text: 'Call Volume',
    },
    stacked: true,

  },
  y2: {

    position: 'right',
    title: {
      display: true,
      text: 'Engagement KPI',
    },
    stacked: true,
  },
},
Enter fullscreen mode Exit fullscreen mode

};

return ;
};

export default StackedBar;

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay