help me with bar chart!

I want to make a programm that draws a bar chart just like the simple one in MS Excel. The problem is to calculate tic labels with the nicest round numbers for Y axis. For example, if a max value is 20 then there are 4 tics Y axis with a step equal to 5, if max val.= 100 then there are 5 tics with a step = 20. In short for ones the step is 0.2 0.5, 1; for tens - 2, 5, 10; for hundreds the step is 20, 50, 100 and so on.