Histogram stacking of c3.js and customization of tooltip

two sets of data, sumData and subData, are stacked together through groups. The original effect is:
on a record, sumData is 10, subdata is 5, but the total height of the bar chart is 15, and the demand is that the total height is 10, in other words, as shown in the figure:

so my problem is how to obtain the value of the corresponding index data2 when modifying the value of data1 in label or tooltip.
questions such as comments on label and tooltip in the code

var chart = c3.generate({
    data: {
        columns: [
            ["data1", 100, 100, 100, 100, 100, 100],
            ["data2", 200, 200, 200, 200, 200, 200],
        ],
        groups: [
            ["data1", "data2"]
        ],
        type: "bar",
        labels: {
            // format: function (v, id, i, j) { return "Default Format"; },
            format: {
                data2: function (value, id, index, j) { 
                    return value+3; //data2value
                },
            }
        }
    },
    tooltip:{
        format: {
            title: function (d) { return "Data " + d; },
            value: function (value, ratio, id) {
                var format = id === "data1" ? d3.format(",") : d3.format("$");
                return format(value);
            }//id
           // value: d3.format(",") // apply this format to both y and y2
        }
    }
});
Feb.09,2022

first of all, you have to review yourself. If you don't read the document carefully, the following solution is attached:
lables has a configuration item as follows

data: {
  labels: {
    format: function (v, id, i, j) { ... }
    // it's possible to set for each data
    //vindexdata1data2console.log
  }
}

then let's talk about tooltip
, which also has a configuration item, as follows

tooltip: {
  contents: function (d, defaultTitleFormat, defaultValueFormat, color) {
    return ... // formatted html as you wanthtml
  }
}

here you can customize the style and data format of tooltip. Parameter d is a data collection, and console.log knows how to do it at once

Menu