If I am given a certain funciton which describes the volume charge density within the sphere with respect to the radius (ρ(r)),how can I calculate the total charge within the sphere.My idea was by calculating the total charge of many infinitesimally small and thin circles. Initially, I though that I could use $$\int (πy^2)*(ρ(r)) \, dr$$ Where $$\ x^2 + y^2 = r^2$$ Because this idea it didnt work i thought of using the areas of small spheres times the volume charge density $$\int (4πr^2)*(ρ(r)) \, dr$$ It worked by I am not sure if this is the proper way or if it was pure luck due to the numbers that i got the answer right.
Even if the 2nd way is right can someone give me some more information in order to understand it better, or is there a better solution which is more understandable.