score:1

Accepted answer

Regarding the tooltip issue: the data for the outer array was bound to the groups that contain the rectangles.

Therefore, you can get it with this.parentNode:

const parentData = d3.select(this.parentNode).datum();

Regarding the sorting issue, you can sort the nested data with:

nestedData.forEach(function(d){
    d.values.sort(function(a,b){
        return a.value - b.value
    });
});

However, this won't make any difference: the order of the bars depend on the domain you passed to x1. So, unless you change the domain for each group (which is not a good practice in data visualisation), you can't sort the bars within groups.

Here is the updated blockbuilder: https://blockbuilder.org/GerardoFurtado/f4b4608bf07588f2b9291ac74c88f82c


Related Query

More Query from same tag