D3.js axis.orient() Function

The d3.axis.orient() Function in D3.js is used to set the orientation and returns the axis. If the orientation is not specified, returns the current orientation which defaults to “bottom”.
Syntax:
axis.orient([orientation])
Parameters: This function accepts a single parameter as mentioned above and described below:
- orientation: This parameter is size to set the orientation of the axis. Four orientation is supported are: “top”, “bottom”. “left” and “right”.
Return Value: This function returns the axis.
Below programs illustrate the d3.axis.orient() function in D3.js:
Example 1:
HTML
| <html>    <head>        <title>          D3.js | d3.axis.orient() Function         </title>          <scriptsrc= "//d3js.org/d3.v3.min.js"></script>    </head>      <body>       <script>       var svg = d3.select("body").append("svg")                   .attr("width", 400)                   .attr("height", 400);                           // Create the Scale we will use for the Axis       var axisScale = d3.scale.linear()                         .domain([0, 100])                         .range([0, 300]);                                 // Create the Axis       var xAxis = d3.svg.axis()                     .scale(axisScale)                     .orient("top");               // Create an SVG group Element for the Axis        // elements and call the xAxis function       svg.append("g")          .attr("transform", "translate(50,50)")          .call(xAxis);       </script>    </body> </html> | 
Output:
Example 2:
HTML
| <html>    <head>        <title>          D3.js | d3.axis.orient() Function         </title>          <scriptsrc= "//d3js.org/d3.v3.min.js"></script>    </head>      <body>       <script>       var svg = d3.select("body").append("svg")                   .attr("width", 400)                   .attr("height", 400);                           // Create the Scale we will use for the Axis       var axisScale = d3.scale.linear()                         .domain([0, 100])                         .range([0, 300]);                                 // Create the Axis       var xAxis = d3.svg.axis()                     .scale(axisScale)                     .orient("left");               // Create an SVG group Element for the Axis        // elements and call the xAxis function       svg.append("g")          .attr("transform", "translate(50,50)")          .call(xAxis);       </script>    </body> </html> | 
Output:
Example 3:
HTML
| <html>    <head>        <title>          D3.js | d3.axis.orient() Function         </title>          <scriptsrc= "//d3js.org/d3.v3.min.js"></script>    </head>      <body>       <script>       var svg = d3.select("body").append("svg")                   .attr("width", 400)                   .attr("height", 400);                           // Create the Scale we will use for the Axis       var axisScale = d3.scale.linear()                         .domain([0, 100])                         .range([0, 300]);                                 // Create the Axis       var xAxis = d3.svg.axis()                     .scale(axisScale)                     .orient("right");               // Create an SVG group Element for the Axis        // elements and call the xAxis function       svg.append("g")          .attr("transform", "translate(50,50)")          .call(xAxis);       </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!
 
				 
					



