As you do exactly this for all plots, maybe this would be worth factorizing in a utility function in common.js maybe?