javascript - How to increase size of pie segment on hover in d3 -


i created pie chart using d3. how increase size of pie segment on hover? can see, green segment small want change size red segment. how can this?

my code:

var w = 400; var h = 400; var r = h/2; var color = d3.scale.category20c();  var data = [{"label":"category a", "value":20},                    {"label":"category b", "value":50},                    {"label":"category c", "value":30},            {"label":"category a", "value":20},                    {"label":"category b", "value":50},                    {"label":"category c", "value":30},            {"label":"category a", "value":20},                    {"label":"category b", "value":50},                    {"label":"category c", "value":5}];   var vis = d3.select('#chart').append("svg:svg").data([data]).attr("width", w).attr("height", h).append("svg:g").attr("transform", "translate(" + r + "," + r + ")"); var pie = d3.layout.pie().value(function(d){return d.value;});  // declare arc generator function var arc = d3.svg.arc().outerradius(r); var arcover = d3.svg.arc()         .outerradius(r + 9);  // select paths, use arc generator draw var arcs = vis.selectall("g.slice").data(pie).enter().append("svg:g").attr("class", "slice"); arcs.append("svg:path")     .attr("fill", function(d, i){         return color(i);     })     .attr("d", function (d) {         // log result of arc generator show how cool :)         console.log(arc(d));         return arc(d);     })      .on("mouseenter", function(d) {             d3.select(this)                .attr("stroke","white")                .transition()                .duration(1000)                .attr("d", arcover)                             .attr("stroke-width",6);         })         .on("mouseleave", function(d) {             d3.select(this).transition()                            .attr("d", arc)                .attr("stroke","none");         });; 

there example in js fiddle : jsfiddle thanks. pie chart

now right code. try it..ok

<!doctype html>  <html>    <head>    <title>dsnap - charts</title>  </head>    <body>    <div id="wrapper">      </div>    <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>    <script>      var canvas = d3.select('#wrapper')        .append('svg')        .attr({          'width': 650,          'height': 500        });        var data = [{        "label": "one",        "value": 40      }, {        "label": "two",        "value": 30      }, {        "label": "three",        "value": 30      }];        var colors = ['red', 'blue'];        var colorscale = d3.scale.linear().domain([0, data.length]).range(colors);        var arc = d3.svg.arc()        .innerradius(0)        .outerradius(100);        var arcover = d3.svg.arc()        .innerradius(0)        .outerradius(150 + 10);        var pie = d3.layout.pie()        .value(function(d) {          return d.value;        });          var renderarcs = canvas.append('g')        .attr('transform', 'translate(440,200)')        .selectall('.arc')        .data(pie(data))        .enter()        .append('g')        .attr('class', "arc");        renderarcs.append('path')        .attr('d', arc)        .attr('fill', function(d, i) {          return colorscale(i);        })        .on("mouseover", function(d) {          d3.select(this).transition()            .duration(1000)            .attr("d", arcover);        })        .on("mouseout", function(d) {          d3.select(this).transition()            .duration(1000)            .attr("d", arc);        });        renderarcs.append('text')        .attr('transform', function(d) {          var c = arc.centroid(d);          console.log(c);          return "translate(" + c[0] + "," + c[1] + ")";        })        .text(function(d) {          return d.value + "%";        });    </script>  </body>    </html>


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -