D3.js log.invert() Function

The log.invert() function returns a value from the domain when a value from the range is given. This inversion is useful for interaction such as determining the data value that corresponds to the position of the mouse.
Syntax:
log.invert(value);
Parameters: This function accepts only one parameter as given above and described below.
- value: A number that belongs to any value in the given range.
Return Value: This function returns a number value that lies in the corresponding domain.
Example 1:
html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" path1tent="width=device-width, initial-scale=1.0" /> </script> </head> <body> <script> var log = d3.scaleLog() .domain([10, 130]) .range([0, 960]); console.log("log(130):", log(130)); console.log("log.invert(960): ", log.invert(960)) console.log("log(log.invert(15)):", log(log.invert(960))); </script> </body> </html> |
Output:
Example 2:
html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" path1tent= "width=device-width, initial-scale=1.0"/> </script> </head> <body> <script> var log = d3.scaleLog() .domain([10, 130, 140]) .range([0, 96, 500]); console.log("log(140):", log(140)); console.log("log.invert(500): ", log.invert(500)) console.log("log(log.invert(500)):", log(log.invert(500))); </script> </body> </html> |
Output:
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!




