Fix bugs introduced in the last commit.
1) properly register "ready" and "error" listeners.
2) update chart type if it changes