d3.js : Applying styles to individual lines

前端 未结 2 1193
感情败类
感情败类 2021-01-29 03:58

Was trying out the draggable network and wanted to be able to use different colours for different links. When I commented out the lines

/*var link = svg.append         


        
2条回答
  •  独厮守ぢ
    2021-01-29 04:20

    To make your links visible

    Do this

    var link = svg.append("g")
                 .selectAll("line");
    

    Instead of

    var link = svg.append("g");
    

    Now you can see all your links in orange color.

    To apply styles to individual lines

    Add class names using conditions like this.

    link.data(graph.links).enter()
         .append("line")
         .attr("class",function(d){     
              return (d.source.x>400 && d.source.y<300)?'link-b':'link-r';
         });
    

提交回复
热议问题