How to use d3.js to draw a line segment with multiple nodes?

clipboard.png
want to use D3.JS to achieve the effect of the above figure, and display other data corresponding to the selected time period.
but since using D3 for the first time, it"s not clear what layout to choose.
after looking at the relevant documents, the first thing that comes to mind is the tree layout with only one branch.
but because the given time period is not fixed, the children of the tree node is dynamically generated according to the background value, which is very inconvenient.
is there any layout that suits this requirement?

Jun.18,2021

spent two days nibbling at a little D3.JS book,
basic implementation process is to draw the canvas, determine the location of each point in the canvas, and then use the line generator to connect, add p and text tags on each point, draw the origin, add date and xxxx content.

// dataset
var dataset = [{
    {
        count: 0,
        data: [
            {
                fieldValue: ''
            },
            {
                fieldValue: ''
            },
            {
                fieldValue" ''
            },
            ...
        ],
        time: ''
    }]


// 
var svg = d3.select("-sharprelevanceRuleConfig").append("svg")
        .attr('id','PathId')  
        .attr("width", function(){
            if(dataset.length > 6 ){
                return (80 + dataset.length * 150);        // 
            }else{
                return 960;                                // 
            }
        })
        .attr("height", height-80)  
        .append("g")

// 
var lines = [];
var x = 60;
var y = 180;
for(var index in dataset){
    lines.push([x,y]);
    x += 150;        // 150px
}

// 
var linePath = d3.svg.line();

// 
svg.append('path')
        .attr('d', linePath(lines))        // 
        .attr('stroke', '-sharp666')
        .attr('stroke-width', '1px')
        .attr('fill', 'none');
                        
var addNode = function(i){
    var self = this;
    var nodeData = [dataset[i]];
    var siteSave = [];
    var node = svg.selectAll()
    .data(nodeData)
    .enter()
    .append('g')
    .attr('transform',function(d){
        var x = 60 + 150 * i;
        var y = 180;
        return 'translate(' + x + ',' + y +')'
    })

    //   
    node.append("circle")
        .attr("r", 5)
        .attr('fill','-sharpf4952d');

    // 
    node.append("text")
        .attr("dx", -30)        //x  
        .attr("dy", function(d){ return i%2?-42:50})        //y  
        .attr('fill','-sharpf4952d')
        .style("text-anchor", 'start')//
        .style('font-family','Times New Roman')
        .text(function(d) { return d.date; });
                    
    // 
    node.append("rect")
        .attr('width',85)
        .attr('height',25)
        .attr("x", -40)        //x  
        .attr("y", function(d){ return i%2?-60:31})        //y
        .attr("rx", 5)        //  
        .attr("ry",5)        //
        .attr('fill','none')
        .attr("stroke", '-sharpf4952d')

    for(var j in nodeData[0].name){
        //
        node.append("text")
            .attr("dx", -30)
            .attr("dy", function(d){
                if(!(i%2)){
                    if(d.count > 5){
                        return -60 + -25 * j;
                    }else{
                        return -15 - 25 * j;
                    }
                }else{
                    return 25 + 25*j;
                }
            })
            .attr('class','siteName')
            .attr('value',function(d){ return d.date})
            .attr('class',function(d){ return d.date})
            .style("text-anchor", 'start')        //  
            .text(function(d) { return d.name[j]; })
            //
            .on('mouseover',function(){
                var className = $(this).attr("value");
                $('.' + className).css({'font-size':'16px','fill':'-sharpf4952d','cursor':'pointer','transition':'all 0.5s ease','-moz-transition': 'all 0.5s ease','-webkit-transition':' all 0.5s ease','-o-transition':'all 0.5s ease'})
            })
            .on('mouseout',function(){
                var className = $(this).attr("value");
                $('.' + className).css({'font-size':'14px','fill':'-sharp333','transition':'all 0.2s ease','-moz-transition': 'all 0.2s ease','-webkit-transition':' all 0.2s ease','-o-transition':'all 0.2s ease'})
            })
            .on('click',getData);
    }

    if(nodeData[0].count == 0){
        node.append("text")
            .attr("dx", -25)
            .attr("dy",function(){
                if(!(i%2)){
                    return -15;
                }else{
                    return 25;
                }
            })
            .text('')
            .style('fill','-sharp999')
            .style('font-size','14px')
            .style('font-family','Microsoft Yahei')
    }

    if(nodeData[0].count > 5){
        // "..." 
        node.append("text")
            .attr("dx", -30)
            .attr("dy", function(d){
                if(!(i%2)){
                    return -40;
                }else{
                    return 145;
                }
            })
            .attr('value',function(d){ return d.date})
            .attr('class',function(d){ return d.date})
            .style("text-anchor", 'start')//  
            .text('...')
            .on('click',getData);
                            
        // 
        node.append("text")
            .attr("dx", -30)
            .attr("dy", function(d){
                if(!(i%2)){
                    return -15;
                }else{
                    return 170;
                }
            })
            .attr('fill','-sharp666')
            .attr('class','mediaJoin')
            .attr('value',function(d){ return d.date})
            .style("text-anchor", 'start')//  
            .text(function(d) {  return ('' + d.count + ''); })
            .on('click',getData);
    }

}
for(var index in dataset){
    addNode(index)
}
if (dataset.length == 1){
    svg.attr('transform','translate(400,0)')
}else if (dataset.length == 2){
    svg.attr('transform','translate(320,0)')
}else if (dataset.length == 3){
    svg.attr('transform','translate(240,0)')
}else if (dataset.length == 4){
    svg.attr('transform','translate(160,0)')
}else if (dataset.length == 5){
    svg.attr('transform','translate(80,0)')
}else{
    svg.attr('transform','translate(0,0)')
}

clipboard.png

this is the fishbone effect finally realized


@ StupidBear I would like to ask, if some nodes have child nodes and end up drawing like a tree, do you know how to write code? Thank you

Menu