Just started using D3, and do like it very much!
Didn't succeed in creating a rect with SVG linearGradient fill. Did
try 2 options.
1. Create linearGradient object in D3 (seems most elegant options).
Issue: doesn't fill at all and I don't know how to set stop offset and
color.
2. Create linearGradient object in HTML page. Issue: fills fine in
Chrome and Firefox, bot not in Safari.
Would appreciate any help. Below is my code for both options.
1. Code for D3 option
Inside js document to create linearGradient object:
matrixGradientClr = vis.selectAll("color")
.data([0])
.enter().append("svg:linearGradient")
.attr('x1', "0%")
.attr('y1', "0%")
.attr('x2',"100%")
.attr('y2',"100%")
.attr('spreadMethod', "pad");
Inside js document to fill rect:
.attr("fill", matrixGradientClr)
2. Code for HTML option
Inside HTML document:
<svg xmlns="
http://www.w3.org/2000/svg" xmlns:xlink="http://
www.w3.org/1999/xlink">
<defs>
<linearGradient id="matrixLinearGradient"
x1="0%" y1="0%"
x2="100%" y2="100%"
spreadMethod="pad">
<stop offset="0%" stop-color="#00cc00" stop-opacity="1"></stop>
<stop offset="100%" stop-color="#cc0000" stop-opacity="1"></stop>
</linearGradient>
</defs>
</svg>
Inside js document to fill rect:
.attr("fill", 'url(#matrixLinearGradient)')