I've the following data for the stack barchart. When I try to calculate the max value for y-axis, it's giving me 100. It should be 70. Can someone let me know where am I doing wrong?
The snippet follows as below
//DATA
var data = [{
category: "test1",
type1: 10,
type2: 20
},
{
category: "test2",
type1: 30,
type2: 40
}
];
var keys = ["type1", "type2"];
var yScale = d3.scaleLinear()
.range([400, 0]);
var stack = d3
.stack()
.keys(keys)
.order(d3.stackOrderNone)
.offset(d3.stackOffsetNone);
var layers = stack(data);
console.log(d3.max(layers[layers.length - 1], d => (d[0] + d[1])))
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>