- Expert Data Visualization
- Jos Dirksen
- 211字
- 2021-07-09 18:22:45
Standard setup, helper objects, and a gray donut
At this point we've loaded the data, and added the HTML select dropdown element. Now we'll set up the chart, some additional helper objects and draw the gray donut you see when the page initially loads. Like we did in the other samples, first set up the chart:
var margin = {top: 20, bottom: 20, right: 20, left: 45},
width = 700 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var chart = d3.select(".chart")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// container, which holds the pie
var pieContainer = chart.append('g')
.attr("transform", "translate(" + width / 2 + " " + height / 2 + ")")
// use some standard colors
var colors = function(i) { return d3.interpolateReds(i/6); }
Nothing new here, except the last line where we set up the colors we want to assign to the segments of the donut. For this, we use another standard D3 API call: d3.interpolateReds. This function returns a red color based on the provided input. The d3.interpolateReds(0) function returns the value at the left, the d3.interpolateReds(0.5) function the value at the center, and d3.interpolateReds(1) function the value at the right.
推薦閱讀
- Vue.js 3.x快速入門(mén)
- 軟件項(xiàng)目估算
- Learn Type:Driven Development
- Python自然語(yǔ)言處理實(shí)戰(zhàn):核心技術(shù)與算法
- Learning Docker
- Vue.js 2 and Bootstrap 4 Web Development
- Monitoring Elasticsearch
- C++程序設(shè)計(jì)基礎(chǔ)教程
- Serverless架構(gòu)
- C++面向?qū)ο蟪绦蛟O(shè)計(jì)習(xí)題解答與上機(jī)指導(dǎo)(第三版)
- Android程序設(shè)計(jì)基礎(chǔ)
- 51單片機(jī)C語(yǔ)言開(kāi)發(fā)教程
- Django 3.0入門(mén)與實(shí)踐
- Java EE企業(yè)級(jí)應(yīng)用開(kāi)發(fā)教程(Spring+Spring MVC+MyBatis)
- 深入實(shí)踐DDD:以DSL驅(qū)動(dòng)復(fù)雜軟件開(kāi)發(fā)