I need help analyzing the following dataset:
[{
label: "ABC", p1: "23", p2: "3"
},
{
label: "EF", p1: "4", p2: "10"
},
{
label: "GV", p1: "5", p2: "15"
},
{
label: "FD", p1: "9", p2: "5"
},
{
label: "SDF", p1: "20", p2: "10"
},]
My attempt to visualize this data is through the use of the following code snippet:
var keys = ["p1", "p2"];
function draw(data) {
var p = d3.select("body")
.selectAll(".one")
.data(d3.stack().keys(keys)(data))
p.enter()
.append("p")
.attr("class", "one")
var span = p
.selectAll("span")
.data(function(d) { return d})
span
.enter()
.append("span")
.html(function(d) { return d})
span.exit().remove();
}
While the p Elements are successfully created, the span elements are not, highlighting an issue in my implementation.
My goal is to generate a span element for each object in the data array, but my current code is falling short. I seek assistance in resolving this discrepancy.
For reference, here is the link to the code on JSFiddle: https://jsfiddle.net/h2ujjo98/