You don't have a consistent diagram throughout your program. You're referencing something by Diagram, diagram, and myDiagram in different places, and you never initialized it. You also don't seem to have an actual HTML div to hold the diagram. Look at some of the samples to see how we typically do it.
In general, we can't do basic debugging of your code.