1
A
回答
2
首先使颜色类别像下面
var c10 = d3.scale.category10();
定义的颜色作为函数如下面在图
color: function(d,i){console.log(i); return c10(i)},
接下来,我们定义在svg defs
部梯度后nvd3的渲染事件。(阅读内嵌评论)
dispatch: {
renderEnd: function(e) {
//make as many gradient as many slices in the pie.
var grads = d3.select("svg").append("defs").selectAll("radialGradient").data($scope.data)
.enter().append("radialGradient")
.attr("gradientUnits", "userSpaceOnUse")
.attr("cx", 0)
.attr("cy", 0)
.attr("r", "100%")
.attr("id", function(d, i) {
return "grad" + i;
});
//gradient start is white
grads.append("stop").attr("offset", "0.5%").style("stop-color", "white");
//gradient end is the color of the slice
grads.append("stop").attr("offset", "27%").style("stop-color", function(d, i) {
return c10(i);
});
//to the slice add the fill for the gradient.
d3.selectAll(".nv-slice path").attr("fill", function(d, i) { return "url(#grad" + i + ")"; })
}
},
工作代码here
希望这有助于!
相关问题
- 1. 添加多非渐变颜色
- 2. 为谷歌图表api提供渐变颜色绘制饼图
- 3. 如何将叠加颜色添加到chart.js饼图分段?
- 4. 在视图的边框上添加渐变颜色
- 5. BRT:使用gbm.perspec为交互图添加渐变颜色
- 6. Javascript颜色渐变
- 7. 颜色渐变(ColdFusion)
- 8. 在Plotband上添加渐变色高图
- 9. 在R中添加颜色渐变到geom_rect
- 10. 如何添加渐变颜色到使用UIBezierPath创建的CAShapeLayer
- 11. 如何渐变颜色添加到背景DIV
- 12. nvd3-angular中的自定义饼图颜色
- 13. 如何在NVD3饼图中自定义颜色
- 14. 如何在XCode 6中为UISlider添加渐变色彩颜色?
- 15. 用颜色制作颜色渐变:
- 16. 如何将渐变颜色或图像添加到iPhone中的文本dev
- 17. AchartEngine中折线图的渐变颜色
- 18. ggplot2图例颜色渐变调整
- 19. ggplot2带颜色渐变的圆环图
- 20. 逐渐改变颜色
- 21. CSS创建颜色渐变
- 22. 渐变颜色拉斐尔
- 23. FabricJS渐变颜色值
- 24. 生成颜色渐变
- 25. 颜色渐变的背景
- 26. 带颜色渐变的UIBeziepath
- 27. DarkGDK颜色渐变代码
- 28. Three.js行的颜色渐变
- 29. textcolor的颜色渐变
- 30. 生成颜色渐变