Do it the other way round: calculatate the width of the bars from the canvas size.

Uwe