I have the code below. I want to separate each bar within each category so they do not overlap. This code is definitely not working as intended. Could you please help to fix the code so I get the desired output?
<!DOCTYPE html>
<html>
<head>
<title>Apache ECharts - Multiple X-Axes with Separated Bars</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/echarts.min.js"></script>
</head>
<body>
<div id="chart" style="width: 600px; height: 400px"></div>
<script>
const xAxisData1 = ["Category 1", "Category 2", "Category 3"];
const xAxisData2 = ["Category A", "Category B", "Category C"];
const xAxisData3 = ["Category X", "Category Y", "Category Z"];
const seriesData1 = [100, 200, 150];
const seriesData2 = [300, 150, 250];
const seriesData3 = [50, 100, 200];
const chart = echarts.init(document.getElementById("chart"));
const options = {
grid: [
{ left: 50, right: 10 }, // grid for the first x-axis
{ left: 150, right: 10 }, // grid for the second x-axis
{ left: 250, right: 10 }, // grid for the third x-axis
],
xAxis: [
{
type: "category",
data: xAxisData1,
offset: 0, // no offset for the first x-axis
axisLine: {
onZero: false, // show the axis line on the zero position
},
},
{
type: "category",
data: xAxisData2,
offset: 40, // some offset for the second x-axis
axisLine: {
onZero: false, // show the axis line on the zero position
},
},
{
type: "category",
data: xAxisData3,
offset: 80, // more offset for the third x-axis
axisLine: {
onZero: false, // show the axis line on the zero position
},
},
],
yAxis: {},
series: [
{
type: "bar",
data: seriesData1,
xAxisIndex: 0,
barWidth: `${50 / xAxisData1.length}%`,
barGap: `-100%`,
barCategoryGap: "20%",
itemStyle: {
color: "#c23531", // red color for the first series
},
},
{
type: "bar",
data: seriesData2,
xAxisIndex: 1,
barWidth: 20, // set the bar width to 20px
barGap: "10%",
barCategoryGap: "20%",
itemStyle: {
color: "#2f4554", // blue color for the second series
},
},
{
type: "bar",
data: seriesData3,
xAxisIndex: 2,
barGap: "10%",
barCategoryGap: "20%",
itemStyle: {
color: "#61a0a8", // green color for the third series
},
},
],
};
chart.setOption(options);
</script>
</body>
</html>
The current output?
