[英]Adding multiple groups to radial D3 chart
Sorry if the title is misleading.抱歉,如果标题具有误导性。 Basically I have the following d3 chart:
基本上我有以下 d3 图表:
Which is based on an array of 5 elements, each one containing 3 separate values.它基于一个由 5 个元素组成的数组,每个元素包含 3 个单独的值。 As you can see, the radial chart is grouped into 5 sections (with a gap) and then each section contains the 3 separate values as bar charts.
如您所见,径向图分为 5 个部分(有一个间隙),然后每个部分包含 3 个单独的值作为条形图。
Here is a js fiddle: https://jsfiddle.net/kpu5o7v2/ And my data:这是一个 js 小提琴: https://jsfiddle.net/kpu5o7v2/我的数据:
[
{
index: 0,
name: "John",
red: 35,
green: 16,
blue: 56
},
{
index: 1,
name: "Spencer",
red: 12,
green: 34,
blue: 8
},
{
index: 2,
name: "Alice",
red: 6,
green: 6,
blue: 70
},
{
index: 3,
name: "Cat",
red: 12,
green: 80,
blue: 1
},
{
index: 4,
name: "Dave",
red: 80,
green: 1,
blue: 2
}
]
What I want to know, is how can I also add sections to correspond to the new_data.name value?我想知道的是,我怎样才能添加与 new_data.name 值相对应的部分? ie.
IE。 the wider groups.
更广泛的群体。 So I can then style them indivdually So, for example, for "John":
所以我可以单独设置它们的样式所以,例如,对于“John”:
Below is an example (if you were to give this group a stroke):下面是一个例子(如果你要给这个组一个中风):
I figured out the answer to this:我想出了这个问题的答案:
let arc2 = d3.arc()
.innerRadius(innerRadius)
.outerRadius((d) => {
return y(ymax);
})
.startAngle(d => {
return x0(d.name)
})
.endAngle(d => {
//let circumference = 2* Math.PI;
//let bandwidth = circumference/names.length;
let endAngle = x0(d.name) + (x0.bandwidth() * 0.8);
return endAngle;
})
.padAngle(0.01)
.padRadius(innerRadius);
svg.append("g")
.selectAll("path")
.data(new_data)
.enter()
.append("path")
.attr('fill', d => {
return "none";
})
.attr("stroke", "#333")
.attr("stroke-width", 2)
.attr("d", arc2);
New JS Fiddle: https://jsfiddle.net/kpu5o7v2/1/新的 JS 小提琴: https://jsfiddle.net/kpu5o7v2/1/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.