Realizing transmissive and reflective focusing with an on-chip metalens