Apr 5, 2026

When creating charts you will often find it useful to convert a value from the data to a pixel value. Take a value in one range, and convert it to a value in another range. This is called a linear map function. Useful for microcontroller projects as well (esp. analog sensors).

function mapRange( value, inMin, inMax, outMin, outMax ) {
  return ( ( value - inMin ) * ( outMax - outMin ) ) / ( inMax - inMin ) + outMin;
}
Back to Notes