0
我有一张我在d3中构建的图表,并且我想在条纹中加入条纹条。我在SVG工作杆的测试版本:将SVG条纹图案翻译为d3
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 64 64">
<defs>
<pattern id="diagonalStripes" x="0" y="0" width="8" height="8" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
<rect x="0" y="0" width="2" height="15" style="stroke:none; fill:purple;" />
<rect x="2" y="0" width="2" height="15" style="stroke:none; fill:green;" />
<rect x="4" y="0" width="2" height="15" style="stroke:none; fill:red;" />
<rect x="6" y="0" width="2" height="15" style="stroke:none; fill:yellow;" />
</pattern>
</defs>
<rect x="0" y="0" width="5" height="15" style="fill:url(#diagonalStripes);"></rect>
</svg>
但是,当我试图标记之间的信息转换成D3只有第一条(紫色的)最多显示:
svg.append('defs')
.append('pattern')
.attr('id', 'diagonalStripes')
.attr('patternUnits', 'userSpaceOnUse')
.attr('patternTransform', 'rotate(45)')
.attr('width', 8)
.attr('height', 8)
.append('rect')
.attr("x",0)
.attr("y",0)
.attr('width', 2)
.attr('height', 15)
.attr('style',"stroke:none; fill:purple;")
.append('rect')
.attr("x",2)
.attr("y",0)
.attr('width', 2)
.attr('height', 15)
.attr('style',"stroke:none; fill:yellow;")
.append('rect')
.attr("x",4)
.attr("y",0)
.attr('width', 2)
.attr('height', 15)
.attr('style',"stroke:none; fill:red;")
.append('rect')
.attr("x",6)
.attr("y",0)
.attr('width', 2)
.attr('height', 15)
.attr('style',"stroke:none; fill:green;");
svg.append("rect")
.attr("x", 10)
.attr("width", 10)
.attr("height", 10)
.attr('fill', 'url(#diagonalStripes)')
显然d3不处理将多个矩形附加到单个模式,但我应该如何正确格式化第一部分才能获得我期望的条纹栏?
谢谢。并感谢您解释为什么我的方法不起作用。我很感激你花时间来解释究竟发生了什么。 – medievalmatt