Barcelona, on Spain's eastern coast, offers a Mediterranean climate moderating temperatures. Unlike Madrid, summer can be humid, and nighttime temperatures don't drop much, as you can see by the short bars on the graph, which can lead to sleepless nights among those sensitive staying in hotel rooms that aren't air conditioned.
October is the rainiest month in Barcelona, with the rainfall peaking at a little under 4 inches. Spring storms are possible, but they can be quite spectacular for folks toting a camera.
Barcelona's proximity to the Atlantic means that summers aren't as dry as most Mediterranean cities.
Spring and Fall are the best times to visit. You can swim in the Mediterranean from late June to October. If you must go in Summer, reserve your lodging in advance, as this is the major vacation time in Europe.
The charts below show the historic high and low temperatures in Barcelona month by month, and the yearly month by month precipitation totals.