Reorder elements of SVG ( z-index ) in D3.js

前端 未结 2 1603
再見小時候
再見小時候 2021-01-02 06:46

I realise this question has been asked before but I can\'t get to the bottom of it.

Here is my chart... http://www.gogeye.com/financialnews/piechart/index3.html

2条回答
  •  盖世英雄少女心
    2021-01-02 07:01

    I am using the D3.js, and found that it has a built-in function for changing the z-order of SVG elements programmatically after the original drawing.

    RipTutorial: svg--the-drawing-order covers the d3 builtin function

    Quotes from this link:

    selection.raise(): Re-inserts each selected element, in order, as the last child of its parent. selection.lower(): Re-inserts each selected element, in order, as the first child of its parent.

    d3.selectAll("circle").on("mouseenter", function(){
        d3.select(this).raise(); 
    });
    
    d3.selectAll("circle").on("mouseleave", function(){
        d3.select(this).lower(); 
    });
    
    

    see live example their jsFiddle

提交回复
热议问题