You could try using this visual as a template and gradually replacing it with your code.
Not sure if it makes any difference, but I noticed the barchart source from the link above does not capitalize "d3" which is capitalized in the error you attached.
Cannot find namespace 'D3'