I am creating some charts for elevation v distance data.
The original source of the data is GPX files and from them I have extracted...
The total route distance (km) and each point along the route as [lat, long, elevation, distFromStart]
The chart plots distanceFromStart (X-axis) v elevation (Y-axis).
The routes can be anything of length between 0.5km and 450km.
The issue I have is with calculating the divisions (the tick values) for the x-axis of the graph. The tick values should always be easy to read, rounded values. The number of ticks is flexible from 5 - 12 (or thereabouts).
A distance (in km)
A list of acceptable tick values (0.1km, 0.2km, 0.5km, 1km, 2km, 5km, 10km, 20km, 50km)
How can I calculate which acceptable tick value I should use and the number of ticks on the x-axis?