A stable Q-switched laser is useful in the area of remote sensing, range finding, optical imaging, material processing, and fiber communications. With its excellent linear and nonlinear optical characteristics, graphene has been proven to be an attractive material to generate nanosecond, picosecond and femtosecond laser pulses. It has a lot of advantages, such as lower saturation intensity, larger saturable-absorption modulation depth, higher damage threshold, sub-picosecond recovery time and an ultrabroad wavelength-independent saturable-absorption range. In this paper, we demonstrate a graphene based Q-switched fiber laser. Graphene was deposited on the fiber interface by the optically driven deposition method. The thickness of the graphene can be controlled by changing depositing time. The compact Q-switched erbium-doped fiber laser based on graphene operated stably, and got Q-switched pulse sequences output with the repetition rate of 19KHz and the average power of 1.4mW when pump power is 40mW. Higher peak power, shorter pulse duration, and higher repetition rate could be achieved by adjusting the thickness of the graphene layer appropriately. Besides, the pulse duration and output power is proved to be a function of the pump power. The repetition rate of this fiber laser had a characteristic of monotonically increasing, near-linear with the changing of pump power. The stable Q-switching pulse output can be observed on the oscilloscope with differently specific repetition rate and pump power. Theory analysis of this fiber laser and further improvement methods is also studied combined with the experimental results.