- Expert Data Visualization
- Jos Dirksen
- 254字
- 2021-07-09 18:22:46
Create the background donut
The final setup we need to do before connecting the loaded data to arc segments is setting up the gray donut you see when the first data is loaded. For this, we use the d3.arc() function:
var arc = d3.arc()
.outerRadius(height/2 * 0.6)
.innerRadius(height/2 * 0.3);
// add a grey background arc
pieContainer.append('path')
.attr("class", 'backgroundArc')
.attr("d", arc({startAngle: 0, endAngle: 2 * Math.PI}));
The d3.arc() function isn't an SVG element we can add to the page, but it is a generator. A generator is a function that, when called, returns a path string that we can then add to a path element. Besides a generator for arc segments, D3 also provides generators for lots of other structures, as we'll see throughout this book. In this case, the generator allows us to create donut or pie segments as SVG paths that we can add. In the previous code, we used this to create a full donut: arc({startAngle: 0, endAngle: 2 * Math.PI}). Note that we've also could have specified these two properties when we called d3.arc() to create the generator. The following properties and functions are available on the d3.arc() function:

Finally, let's add some CSS for this arc, and a nice border around the main container:
.backgroundArc {
fill: #ddd;
}
.chart {
margin: 10px;
border-radius: 5px;
border: solid #555555 thin;
background-color: #eee;
}
We have our basic setup, which at this point looks like this:

Not very exciting yet, so let's add the colored segments that make up the donut.
- Intel Galileo Essentials
- Design Principles for Process:driven Architectures Using Oracle BPM and SOA Suite 12c
- 面向STEM的Scratch創新課程
- PLC編程及應用實戰
- Java應用開發技術實例教程
- 大學計算機基礎實驗指導
- Application Development with Swift
- Mastering SciPy
- AI自動化測試:技術原理、平臺搭建與工程實踐
- Microsoft Exchange Server 2016 PowerShell Cookbook(Fourth Edition)
- Learning Gerrit Code Review
- Python自動化開發實戰
- MATLAB/Simulink建模與仿真
- HTML+CSS+JavaScript前端開發(慕課版)
- CorelDRAW X6中文版應用教程(第二版)