简体   繁体   English

d3.js雷达图-在行之间填写

[英]d3.js Radar Graph - filling in between lines

I'm trying to create a fill in between two of these triangles, for example a red fill in between the red and green triangles. 我试图在两个三角形之间创建一个填充,例如在红色和绿色三角形之间创建一个红色填充。 Does anybody know how to accomplish this? 有人知道怎么做到这一点吗? I have seen another example of a radar graph that I believe does something similar, although I think they create the fill using CSS, not d3... 我看过雷达图的另一个示例,尽管我认为他们使用CSS而不是d3创建填充,但我相信它也做了类似的事情。

在此输入图像描述

solved the above problem with mbostock's answer using radial chart... 使用径向图解决了mbostock的答案的上述问题...

Final Result 最后结果 在此输入图像描述

You don't need to implement a custom path for this; 您不需要为此实现自定义路径; you can use a d3.svg.area.radial path generator. 您可以使用d3.svg.area.radial路径生成器。 Here's an example of a stacked radial area chart which you might use to plot cyclical data: 这是一个堆积的径向面积图的示例,可用于绘制周期性数据:

The implementation is fairly similar to a radar chart, except with a radar chart the scales will be different for each angular point. 该实现与雷达图非常相似,不同之处在于使用雷达图时,每个角点的比例都不同。

To achieve this, you'll have to merge the two triangles into one path by using a custom path generator. 为此,您必须使用自定义路径生成器将两个三角形合并为一条路径。 Then you can close the path and fill it. 然后,您可以关闭路径并填充它。 Note that if you want the triangles to have different colours, you need to draw them separately. 请注意,如果希望三角形具有不同的颜色,则需要分别绘制它们。

You could try to cheat and simply fill the bigger triangle and then put the smaller triangle with a white fill on top of it. 您可以尝试作弊并简单地填充较大的三角形,然后在较小的三角形上添加白色填充。 Then draw the grid lines. 然后绘制网格线。 This will only work however if the triangles don't overlap. 但是,这仅在三角形不重叠的情况下有效。

As Lars mentioned, you want to create an SVG Path element . 如Lars所述,您想创建一个SVG Path元素

Paths are defined by a series of commands in the d attribute on the element. 路径由元素上d属性中的一系列命令定义。 You want to start by moving absolutely ("M") to one corner of one of the two triangles. 您想从绝对(“ M”)移动到两个三角形之一的一个角开始。 Then you'll want to use the lineto ("L" absolutely, or "l" relatively) to go to each corner of the first triangle. 然后,您将需要使用lineto(绝对为“ L”或相对为“ l”)转到第一个三角形的每个角。 Then move absolutely to the other triangle, and repeat. 然后绝对移动到另一个三角形,然后重复。 The "z" at the end closes the path. 末尾的“ z”关闭路径。 Set the fill on the path to the desired color. 将路径上的填充设置为所需的颜色。

Here's an example path from the link above for a single triangle: 这是上面链接中单个三角形的示例路径:

<path d="M 100 100 L 300 100 L 200 300 z"/>

mbostock uses on paths for the bar charts at http://square.github.com/crossfilter/ if you want to look at this technique in action. 如果您想了解这种技术,mbostock可以在http://square.github.com/crossfilter/上使用条形图的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM