官术网_书友最值得收藏!

Adding the dropdown

The dropdown is just a standard select HTML element, which is added to the HTML file:

<p> 
<span>
Select group:
</span>
<select>
<option value="All" selected>All</option>
<option value="Female">Female Owners</option>
<option value="Male">Male Owners</option>
<option value="AfricanAmerican">African American Owners</option>
<option value="White">White Owners</option>
</select>
</p>

With just this code, nothing will happen when we select one of the entries in the dropdown. We still need to connect this dropdown to our JavaScript. We do this directly using D3:

var select = d3.select('select').on('change', update); 

...

function update() {
var show = select.property('selectedOptions')[0].value;
updateCircle(show);
}

We select the select element, and use the on function to add an event listener. Now, whenever the value of the dropdown changes, the update function will be called. In this update function we just call the updateCircle function with the value of the dropdown. As we'll see later on in the updateCircle function, this will cause the donut to be redrawn with a different set of data.

主站蜘蛛池模板: 大埔区| 定兴县| 沁源县| 阿尔山市| 焉耆| 故城县| 南丰县| 台中县| 林周县| 怀仁县| 雷波县| 宿迁市| 景泰县| 安吉县| 剑河县| 上虞市| 隆回县| 秭归县| 乐安县| 博白县| 阳春市| 临桂县| 清新县| 东莞市| 井冈山市| 荣成市| 宜宾县| 华亭县| 凤山市| 永宁县| 独山县| 新邵县| 万载县| 仙游县| 南京市| 铜山县| 寿阳县| 聂荣县| 安宁市| 靖州| 宁明县|