I think the issue is most probably because the onload event has fired even before your script tag is executed. So instead of placing the script tag inside the div element place it just before the end of head tag. Entire CanvasJS website uses Bootstrap.
Also, onload is not the best way to go. We are using onload in all the examples just to keep it simple and so that we don’t rely on any other libraries. Better approach is to use jQuery’s ready method.