Using the two-component model that includes charmonium production from both initial nucleonnucleon hard scattering and regeneration in the produced quark-gluon plasma, we study J/ψ production in heavy-ion collisions at the SPS, RHIC and LHC. For the expansion dynamics of produced hot dense matter, we use a schematic viscous hydrodynamic model with the specific shear viscosity in the quark-gluon plasma and the hadronic matter taken, respectively, to be twice and ten times the lower bound of 1/4π suggested by the AdS/CFT correspondence. For the initial dissociation and the subsequent thermal decay of charmonia in the hot dense matter, we use the screened Cornell potential to describe the properties of charmonia and perturbative QCD to calculate their dissociation cross sections. Including regeneration of charmonia in the quark-gluon plasma via a kinetic equation with in-medium chamonium decay widths, we obtain a good description of measured J/ψ nuclear modification factors in Pb+Pb collisions at √ sNN = 1.73 GeV at SPS and in Au+Au collisions at √ sNN = 200 GeV at RHIC. A reasonable description of the measured nuclear modification factor of high transverse momenta J/ψ in Pb+Pb collisions at √ sNN = 2.76 TeV at LHC is also obtained.