const canvas = d3.select(".canva"); let data_array = [4, 15, 34]; // Add SVG element // const svg = canvas.append("svg") // .attr('width', '600') // .attr('height', '800'); const svg = canvas.select("svg"); const rect = svg.selectAll("rect"); rect.attr("width", 24) .data(data_array) .attr("fill", "orange") .attr("height", function(d) { // d is from data_array return d*2; }) .attr("x", function (d, i) { // i = index of the rect[] svgs console.log(d); return i * 25; }) console.log(rect);