D3.js areaRadial.context() Method Last Updated : 02 Sep, 2020 Comments Improve Suggest changes Like Article Like Report The areaRadial.context() method in D3.js lets you specify the canvas element’s context in which the area radial would be rendered. The area radial will be rendered in the current context when the generator is invoked. We can set the context of the area on our own using this method like color, stroke, fill, etc. The default value is null. Syntax: d3.areaRadial.context( _context ) Parameters: This method accepts a single parameter as mentioned above and described below: _context: It is context set by the user. Return Value: This method returns the current context. Below given are a few examples of areaRadial.context() method in D3.js: Example 1: HTML <!DOCTYPE html> <html> <head> <script src= "https://d3js.org/d3.v5.min.js"> </script> </head> <body> <h1 style="text-align: center; color: green;"> GeeksforGeeks </h1> <h3 style="text-align: center;"> D3.js | areaRadial.context() Method </h3> <center> <canvas id="gfg" width="200" height="200"> </canvas> </center> <script> var points = [ { x: 0, y: 0 }, { x: 2, y: 3 }, { x: 4, y: 1 }, { x: 6, y: 8 }, { x: 8, y: 17 }, { x: 10, y: 15 }, { x: 12, y: 20 }]; // Get the context var context = d3.select("#gfg") .node() .getContext("2d"); var xScale = d3.scaleLinear() .domain([0, 6]) .range([0, 2 * Math.PI]); var yScale = d3.scaleLinear() .domain([0, 20]) .range([90, 30]); var Gen = d3.areaRadial() .angle(d => xScale(d.x / 2)) .innerRadius(d => yScale(d.y) / 2) .outerRadius(d => yScale(d.y)) // Specify the context // to be used .context(context); context.translate(100, 100); Gen(points); context.strokeStyle = "black"; context.fillStyle = "green"; context.fill(); context.stroke(); </script> </body> </html> Output: Example 2: HTML <!DOCTYPE html> <html> <head> <script src= "https://d3js.org/d3.v5.min.js"> </script> </head> <body> <h1 style="text-align: center; color: green;"> GeeksforGeeks </h1> <h3 style="text-align: center;"> D3.js | areaRadial.context() Method </h3> <center> <canvas id="gfg" width="200" height="200"> </canvas> </center> <script> var data = [ { x: 10, y: 1 }, { x: 15, y: 3 }, { x: 20, y: 5 }, { x: 25, y: 7 }, { x: 30, y: 9 }, { x: 35, y: 11 }, { x: 40, y: 13 }]; // Get the context var context = d3.select("#gfg") .node() .getContext("2d"); var xScale = d3.scaleLinear() .domain([0, 6]) .range([0, 2 * Math.PI]); var yScale = d3.scaleLinear() .domain([0, 20]) .range([90, 30]); var Gen = d3.areaRadial() .angle(d => xScale(d.x / 2)) .innerRadius(d => yScale(d.y) / 2) .outerRadius(d => yScale(d.y)) // Specify the context // to be used .context(context); context.translate(100, 100); Gen(data); context.strokeStyle = "black"; context.fillStyle = "green"; context.fill(); context.stroke(); </script> </body> </html> Output: Comment More info T taran910 Follow Improve Article Tags : JavaScript D3.js Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings6 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in Javascript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readJavascript Scope3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like