I am looking for hatch fill in a pie chart area. Like this
i have find hatch fill code form here
So i have to clone path attribute and give it fill:url(#diagonalHatch) .Its working if i do it manually in chrome. it shows the pattern
Now i want to clone that path and give that attr and insert it to sibling. I am trying to access that path but not successful. fiddle here . if someone had jquery solution it would be fine too. My current code
var testdata = [
{
key: "eight two%",
y: 82
},
{
key: "eighteen%",
y: 18
}
];
nv.addGraph(function() {
var width = 500,
height = 500;
var chart = nv.models.pieChart()
.x(function(d) { return d.key })
.y(function(d) { return d.y })
.color(['red','green'])
.width(width)
.height(height);
d3.select("#test1")
.datum(testdata)
.transition().duration(1200)
.attr('width', width)
.attr('height', height)
.call(chart);
var svg = d3.select("#test1");
svg
.append('defs')
.append('pattern')
.attr('id', 'diagonalHatch')
.attr('patternUnits', 'userSpaceOnUse')
.attr('width', 4)
.attr('height', 4)
.append('path')
.attr('d', 'M-1,1 l2,-2 M0,4 l4,-4 M3,5 l2,-2')
.attr('stroke', '#000000')
.attr('stroke-width', 1);
return chart;
});
var svg2 = d3.select("#test1");
var node = svg2.select(".nv-slice path").attr('d');
console.log(node);