Why need the capacitors be as close as possible to the device?
Is that the inductance, 


Yes


  resistance 


Yes


  or maybe impedance of the PCB track 


Yes


  or wire 


Yes


  that affects the electric charge?


hmm .. it affects the electric current, not so much the charge. The current from capacitor to decoupled device must meet as little "obstruction" as possible.

Devices can have huge inrush currents when switching and without decoupling this inrush current, together with resistance/inductance of the wiring can cause the power supply voltage to drop below the minimum operational power supply voltage. The decoupling cap is there to prevent this situation. By keeping the loop small, low inductance, low resistance, the capacitor can isolate the inrush current from the actual power supply which has much longer traces/leads and with that higher impedance.