Generalize javascript chart generation code
use same chart generation code everywhere
fix js single line/bar chart bug