It looks to me like your code is placing things in a grid that you've built in world space. The canvas scaler component doesn't help if your grid is in world space.
Instead of manually creating a grid, use the GridLayoutGridLayoutGroup component. This component lets you easily create a grid on a canvas.