Drawing a sector of sunburst diagram using d3.js

风流意气都作罢 提交于 2019-12-08 07:12:49

问题


I need to draw a sunburst diagram like this:

As you can see , this is actually a sector of sunburst diagram. Can I set a startAngle and endAngle for the main circle/arc?

Edit: My diagram is like: https://bl.ocks.org/mbostock/4063423


回答1:


Is this what you are looking for ?

Here is the changing part :

var partition = d3.layout.partition()
    .sort(null)
    .size([Math.PI, radius * radius]) // Previoulsy : .size([2 * Math.PI, radius * radius])
    .value(function(d) { return 1; });

var arc = d3.svg.arc()
    .startAngle(function(d) { return d.x - Math.PI / 2; }) // Previously : .startAngle(function(d) { return d.x; })
    .endAngle(function(d) { return d.x + d.dx - Math.PI / 2; }) // Previously : .endAngle(function(d) { return d.x + d.dx; })
    .innerRadius(function(d) { return Math.sqrt(d.y); })
    .outerRadius(function(d) { return Math.sqrt(d.y + d.dy); });

See live demo : JSFiddle




回答2:


You definitely can set startAngle and endAngle to circle.

see code snippest from sunburst diagram.

var arc = d3.svg.arc()
        .startAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x))); })
        .endAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))); })
        .innerRadius(function(d) { return Math.max(0, d.y ? y(d.y) : d.y); })
        .outerRadius(function(d) { return Math.max(0, y(d.y + d.dy)); });


来源:https://stackoverflow.com/questions/38138625/drawing-a-sector-of-sunburst-diagram-using-d3-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!