First things first, you can play with all the code of the component and the data here: CodeSandBox
I have a Timeline
component in d3
, and for each one of the circles I want to show the respective data in the tooltip according to the day of the month. As you can see in the image, I can do it, the problem here is that in all the tooltips it only shows the first properties value of data .info
. It doesn’t do the “loop” through the tooltips , like it does for the colors of the circles… and I really think that it’s because of the generation of only and exclusive one tooltip per event… i really don’t know how to solve this problem as I tried multiple things.
data.tsx:
const data = [
{
tag: "Vários",
date: "2021-01-01 00:00:00",
info: [
{
tag: "Prescrição",
date: "2021-01-01 00:00:00",
healthProf: "Dr. Ana Martins Noronha"
},
{
tag: "Avaliações",
date: "2021-01-01 00:00:00",
healthProf: "Dr. João Palmeira"
}
],
category: {
tag: "Vários",
color: "#999999"
}
},
{
tag: "Prescrição",
date: "2021-01-02 00:00:00",
info: [
{
tag: "Diagnõsticos",
date: "2021-01-02 00:00:00",
healthProf: "Dr. Roberto Ladeiras"
}
],
category: {
tag: "Prescrição",
color: "#4199e0"
}
}, ...
I really think the problem comes from the following logic:
Timeline.tsx
tooltip.each(function (d: any, index: number) {
for (var i = 0; i < d.info.length; i++) {
tooltip
.append("span")
.text((d: any) => {
return `${d.info[i].tag}: `;
})
.attr("width", "1250px")
.style("color", "#ffffff")
.style("text-transform", "uppercase")
.style("font-weight", "bold")
.style("padding", "0")
.style("font-size", "10px");
tooltip
.append("span")
.style("font-weight", "regular")
.text((d: any) => {
return d.info[i].date;
})
.style("color", "#ffffff")
.style("font-size", "10px");
tooltip
.append("div")
.style("font-weight", "regular")
.text((d: any) => {
return d.info[i].healthProf;
})
.style("color", "#ffffff")
.style("font-size", "10px");
}
});