Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • TypeScript
  • Vue.js
  • D3.js
  • Collect.js
  • Underscore.js
  • Moment.js
  • Ember.js
  • Tensorflow.js
  • Fabric.js
  • JS Formatter
  • JavaScript
  • Web Technology
Open In App
Next Article:
D3.js | d3.range() function
Next article icon

D3.js | d3.range() function

Last Updated : 09 Feb, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

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.
Syntax: 
 

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.
Example 1: 
 

javascript
<body>     <script src='https://d3js.org/d3.v4.min.js'></script>      <script>              // Calling to d3.range() function         // with parameters start, stop and steps.         A = d3.range(0, 4, 1);         B = d3.range(10, 100, 10);         C = d3.range(5, 50, 5);         D = d3.range(1, 10, 2);                  // Getting an array of arithmetic progression         document.write(A + "<br>");         document.write(B + "<br>");         document.write(C + "<br>");         document.write(D + "<br>");     </script> </body> 

Output: 
 

[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]


Example 2: 
 

javascript
<body>     <script src='https://d3js.org/d3.v4.min.js'></script>      <script>              // Calling to d3.range() function         // with parameters start, stop and steps.         A = d3.range(1, 2);         B = d3.range(10, 20);         C = d3.range(0, 10, 0.5);         D = d3.range(1, 10, 0.9);                  // Getting an array of arithmetic progression         document.write(A + "<br>");         document.write(B + "<br>");         document.write(C + "<br>");         document.write(D + "<br>");     </script> </body> 

Output: 
 

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.
Reference: https://devdocs.io/d3~5/d3-array#range
 


Next Article
D3.js | d3.range() function

K

Kanchan_Ray
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • D3.js

Similar Reads

    D3.js band.range() Function
    The band.range() function in D3.js library is used to set the range of the scale to the specified two-element array of numbers. The default value of the range is [0, 1]. Syntax: band.range([range]); Parameters: This function accepts single parameters as given above and described below. range: This p
    2 min read
    D3.js | d3.scan() function
    The d3.scan() function is a built-in function in D3.js which scans the array linearly and returns the index of the minimum element according to the specified comparator. The function returns undefined when there are no comparable elements in the array. Syntax: d3.scan(array, comparator) Parameters:
    2 min read
    D3.js d3.max() function
    The d3.max() function in D3.js is used to return the maximum value in the given array using natural order. If an array is empty then it returns undefined as output. Syntax:d3.max(Array)Parameters:This function accepts parameters Array which is an array of elements whose maximum value is to be calcul
    2 min read
    D3.js | d3.min() function
    The d3.min() function in D3.js is used to returns the minimum value in the given array using natural order. If an array is empty then it returns undefined as output. Syntax: d3.min(Array) Parameters: This function accepts a parameters Array which is an array of elements whose minimum value is to be
    2 min read
    D3.js d3.quantile() Function
    The d3.quantile() function in D3.js is used to returns the p-quantile of the given sorted array of elements. Where p is the number lies in the range[0, 1]. Syntax: d3.quantile(Array, p) Parameters: This function accept two parameters as mentioned above and described below: Array: It holds the sorted
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences