JSFiddle - React, Tailwind, and code Playground

HTML

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="index.css">
</head>

<body>
<div id="SwapBars"></div>

</body>

</html>

CSS

body {background-color: #f1d6d6;}

rect {
    cursor: pointer;
}

JavaScript

let variables = ["group1", "group2", "group3","group4","group5"]

    let updateData;
    // set the dimensions and margins of the graph
    const margin = {top: 50, right: 30, bottom: 20, left: 50},
        width = 1000 - margin.left - margin.right,
        height = 800 - margin.top - margin.bottom;

    // append the svg object to the body of the page
    const svg = d3.select("#SwapBars")
        .append("svg")
        .attr("width", width + margin.left + margin.right)
        .attr("height", height + margin.top + margin.bottom)
        .append("g")
        .attr("transform", `translate(${margin.left},${margin.top})`);

    // add axis y and x
    const x = d3.scaleBand()
        .domain([0,1,2,3,4,5,6,7,8,9])
        .range([0, width])
        .padding([0.2])
    svg.append("g")
        .attr("transform", `translate(0, ${height})`)
        .call(d3.axisBottom(x).tickSizeOuter(0));

    const y = d3.scaleLinear()
        .domain([0, 100])
        .range([ height, 0 ]);
    svg.append("g")
        .call(d3.axisLeft(y));
    // colors, one for variable
    const color = d3.scaleOrdinal()
        .domain(variables)
        .range(['#e41a1c','#377eb8','#eabd0a','#9137b8','#4daf4a'])

    Drawn();


    function Drawn() {
        var data = [
    {
        "bar_pos": 0,
        "group1": 7,
        "group2": 3,
        "group3": 7,
        "group4": 15,
        "group5": 30
    },
    {
        "bar_pos": 1,
        "group1": 10,
        "group2": 6,
        "group3": 17,
        "group4": 15,
        "group5": 25
    },
    {
        "bar_pos": 2,
        "group1": 4,
        "group2": 3,
        "group3": 7,
        "group4": 15,
        "group5": 15
    },
    {
        "bar_pos": 3,
        "group1": 10,
        "group2": 6,
        "group3": 5,
        "group4": 15,
        "group5": 35
    },
    {
        "bar_pos": 4,
        "group1": 4,
        "group2": 3,
        "group3": 7,
        "group4": 15,
        "group5": 27
    },
    {
        "bar_pos": 5,
...