D3 arc gradient [closed]

I'm trying to create a timer using d3 which has a gradient which will change between 0 and 100%. For example dark orange at 0% and light orange at 100%. I can make the arc transition between dark and light orange but having problems finding anything which allows me to apply a gradient to the arc. An example of what I am trying to achieve can be seen in the image below.

enter image description here

Been searching/frying my brain trying to achieve this for a day or so now.

Answers:

Answer

SVG does not allow for these kind of gradients. I've done something very similar before, I created a "donut chart" where each wedge is a different color:

http://jsfiddle.net/duopixel/GfVrK/

var arc, data, padding, steps = 2, r=400/2, pi = Math.PI;
var padding = 2 * r / 200;
arc = d3.svg.arc()
  .innerRadius(r-40)
  .outerRadius(r).startAngle(function(d) { return d.startAngle; })
  .endAngle(function(d) { return d.endAngle; });

data = d3.range(180).map(function(d, i) {
  i *= steps;
  return {
    startAngle: i * (pi / 180),
    endAngle: (i + 2) * (pi / 180),
    fill: d3.hsl(i, 1, .5).toString()
  };
});

d3.select("#wheel")
  .insert('svg', 'svg')
  .attr("id", "icon")
  .append('g')
    .attr("transform", "translate(" + r + "," + r + ") rotate(90) scale(-1,1)")
    .selectAll('path')
      .data(data)
      .enter()
      .append('path').attr("d", arc)
      .attr("stroke-width", 1)
      .attr("stroke", function(d) { return d.fill;})
      .attr("fill", function(d) { return d.fill; });

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.