Why can not I draw a circle with d3.js in a lightning component?
appl.app
:
<aura:application >
<c:libComp/>
</aura:application>
comp.cmp
:
<aura:component>
<ltng:require scripts="{!$Resource.d3Lib}"
afterScriptsLoaded="{!c.drawACircle}" />
</aura:component>
compController.js
:
({
drawACircle: function () {
//Make an SVG Container
var svgContainer = d3.select("body").append("svg")
.attr("width", 200)
.attr("height", 200);
//Draw the Circle
var circle = svgContainer.append("circle")
.attr("cx", 30)
.attr("cy", 30)
.attr("r", 20)
}
});
According to this I am doing everything correctly.
But here is the error message:
Uncaught TypeError: Cannot read property 'document' of undefined throws at https://oobarbazanoo-dev-ed.lightning.force.com/resource/1527188162000/d3Lib:15:4187
In the d3Lib
I put all that is written over here.