Generalize javascript chart generation code
use same chart generation code everywhere