The weight $$W = mg$$ is neither along the +x or the +y directions. But, it has both x- and y-components. To calculate this, note that triangle ABC is a right-angled triangle, as angle ACB is $$90 ^{\circ}$$. Angle ABC is thus $$90 - \theta$$
Also, as the x-axis is a straight line, we have the $$180^{\circ}$$. From all this, we see that the vector $$\vec{W}$$ makes an angle of $$180 + 90 - \theta = 270 - \theta$$ with the +x-axis.
We know that $$W_x$$ is given by the $$\cos$$ component of the angle the vector makes with the +x-axis. Thus, $$W_x = W \cos \left(270 - \theta \right) = - W \sin \theta$$. Similarly, $$W_y = - W \cos \theta$$. (Note the minus signs! It is because +x and +y are upwards, and weight is acting downwards.)