Solution Review: Make a Scale
Explore how to select and implement the correct D3.js scale for discrete input and output data. Learn to configure scaleOrdinal with domain and range functions to map data effectively. Understand best practices including handling invalid inputs for robust visualizations.
We'll cover the following...
We'll cover the following...
Solution
Explanation
Let’s dive into the following explanation to better understand how the above code works.
- The most important part of this coding challenge is the selection of the correct scale. Both the input and output are discrete, so we have selected the
scaleOrdinalscale and initialized it in line 4. - In line 5, we have set our domain of the
c_scaleto thecoursesarray using thedomain()function. - In line 6, the range of
c_scaleis initialized totimingsusing therange()function. - Using
console.login line 7, we can see the output of thec_scaleon the console.
Note: You can add the unknown function in the solution which will take care of the invalid inputs.