Fix bugs introduced in the previous commit.

Sorry for sending a buggy commit yesterday.  This update fixes two issues:
1) properly register "ready" and "error" listeners.
2) update chart type if it changes