首页 > 其他分享 >D3:改变节点样式

D3:改变节点样式

时间:2022-12-15 09:34:00浏览次数:35  
标签:ac return img 样式 节点 circle data D3

首先在<body>添加图片对象

       
       <svg id="mySvg_ac" width="0" height="0" >
        <defs id="mdef">
            <!-- 图片1  -->
            <pattern id="img_ac" x="0" y="0" height="128" width="128">
            <image x="0" y="0" width="128" height="128" xlink:href="/static/images/ac.png"></image>
            </pattern>

            <!-- 图片2  -->
            <pattern id="img_de" x="0" y="0" height="128" width="128">
            <image x="0" y="0" width="128" height="128" xlink:href="/static/images/de.png"></image>
            </pattern>
        </defs>
       </svg>

然后在需要的节点中引用图片对象

        var nodes = svg.selectAll("circle")
            .data(nodes_data)
            .enter()
            .append("circle")
            .attr("fill", function(d){
                if(d.type == 'ac'){
                    return "url(#img_ac)";
                }else{
                    return "url(#img_de)";
                }})

 

标签:ac,return,img,样式,节点,circle,data,D3
From: https://www.cnblogs.com/carriexu/p/16984277.html

相关文章