The d3.range() function in D3.js is used to return an array containing an arithmetic progression starting from the start parameter and iterated over a sequence of uniformly-spaced numeric value called a step and ends with a stop parameter.
d3.range(start, stop, step)
Parameters: This function accepts three parameter which are illustrated below:-
- start: It is the inclusive integer value which is the first element of the output array. Its default value is 0.
- stop: It is the exclusive integer value which are not added into the output array.
- step: It is the integer value which regularly gets added with the start value and prints the result till stop value arrives.
Return Value: It returns an array containing an arithmetic progression.
Below programs illustrate the d3.range() function in D3.js.
[0,1,2,3] [10,20,30,40,50,60,70,80,90] [5,10,15,20,25,30,35,40,45] [1,3,5,7,9]
1 [10,11,12,13,14,15,16,17,18,19] [0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8,8.5,9,9.5] [1,1.9,2.8,3.7,4.6,5.5,6.4,7.3,8.2,9.1]
Note:In the above code, some range() functions did not take step value so its default value is considered as 1.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.