score:1

Accepted answer

the <defs> element only defines this pattern, it doesn't actually cause it to be rendered anywhere. artifacts defined in a defs need to be referenced by other visible elements.

in order to reference a definition you need to give it a unique id. (note that the defs can live anywhere in the svg and can be referenced by any other element or elements).

rectcanvas_o.append("defs").append("pattern").attr("id", "my_pattern");

then, you need to set the fill attribute of your rect to reference your defined pattern:

rectcanvas_o = parentelement.append("rect")
    .attr("width", "30")
    .attr("height","100%").
    .attr("class", this.currentalarmclass_s)
    .style("fill", "url(#my_pattern)");

Related Query

More Query from same tag