enclosed chart code in an immediate function