I took down my ceiling fan and there are 4 black wires together 3 white wires together and 1 white wire by itself. I want to connect and chandelier there to work by switch. The fan that was up before the fan always had power and the light worked by wall switch
[Edit: I've installed two ceiling fans since writing this answer so I want to amend it.]
Your old ceiling fan will have the light socket circuit and the fan motor circuit separated so that, if one wishes, the two circuits can be separately operated by two wall switches. Modern fans will have a blue wire for one circuit and the other circuit will have a black wire, and both will have a white wire.
Your old ceiling fan must have black wires for both circuits. By wiring both of them with the black wire of the power source that is presumably is switched by the wall switch, both circuits are controlled by one wall switch. This is the normal way to wire a ceiling fan I believe.
So all you have to do is - after turning of electrical service to the room via the breaker box or just to the whole house to be safe - remove the ceiling fan and you'll be left with a hole in the ceiling and the power source wires. Connect the new chandelier to the power source wires - black to black and white to white - and ground the chandelier to the ground wire if there is one. Done. Very very easy. The switch will work the new light just fine assuming that it's not a "switch loop" and that the "1 white wire by itself" is one of the old ceiling fan wires or an old wire not part of the new electrical service.
[The original answer is bellow:]
In general, black wires connect with other black wires and white wires connect with other white wires. I'm not an electrician and I'm sure there are exceptions, but this is the general rule of thumb. Black is the "hot" wire and white is known as "neutral".
If the switch operating the light worked just fine before removing the light/fan, then it should work for your new chandelier light too.
You need to investigate as much as possible to try and find out what the loose white wire is and if it's connected to anything on the other end.
Was the "white wire by itself" connected to the ceiling fan/light, or was it loose in the junction box? It's possible that the ceiling fan and light used the white wire. Is it an old house? It could be old wire that has been superseded by new wiring by a previous homeowner and it's not needed now.
What I would do is I would try to identify what wires connect to what throughout the room. You can do this with a $3 test lamp that checks connectivity to outlets and such (turn power off if you haven't already!!).
If there's still confusion, I would do some trial and error. Connect the 4 black wires and 3 white wires to a lamp socket, and turn the power back on. Can the switch turn the test lamp on and off? If not then try adding the lone white wire to the circuit. Continue like this until it works.
This is what electrical work is all about! Problem solving, plus the willingness to work with electricity and a penchant for safety. If you're not comfortable with any of this then please hire a professional. Hope this helps! :)