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

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.

主站蜘蛛池模板: 故城县| 新巴尔虎左旗| 白河县| 长沙市| 平和县| 台湾省| 沅陵县| 平湖市| 永修县| 商城县| 衡南县| 临武县| 江陵县| 安平县| 南宁市| 新蔡县| 南开区| 小金县| 五家渠市| 宜良县| 广州市| 武平县| 财经| 曲沃县| 关岭| 勐海县| 滨州市| 云林县| 台前县| 民勤县| 甘肃省| 聂荣县| 千阳县| 寿阳县| 太和县| 依安县| 新民市| 乾安县| 洞头县| 永和县| 永寿县|