Why French is an official language?

French is spoken in countries all around the world, from all over Africa to Canada.

is very innacurate. French is an official language in France and some of what used to be its colonies. That is because they developed that language. That's like asking why English is the official language of America. We partially developed it and so we speak it. You will find that most countries who develop a language, unless they develop multiple (then its numbers that count the most), then they speak that language.