- Expert Data Visualization
- Jos Dirksen
- 147字
- 2021-07-09 18:22:45
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.
推薦閱讀
- Boost.Asio C++ Network Programming(Second Edition)
- C++ Primer習(xí)題集(第5版)
- Mastering Selenium WebDriver
- Blockly創(chuàng)意趣味編程
- C#程序設(shè)計(jì)
- Python深度學(xué)習(xí):模型、方法與實(shí)現(xiàn)
- 圖數(shù)據(jù)庫實(shí)戰(zhàn)
- Visual Studio 2015高級編程(第6版)
- C/C++數(shù)據(jù)結(jié)構(gòu)與算法速學(xué)速用大辭典
- Hadoop大數(shù)據(jù)分析技術(shù)
- C語言程序設(shè)計(jì)
- Python Machine Learning Cookbook
- 分布式數(shù)據(jù)庫HBase案例教程
- JBoss AS 7 Development
- C語言從入門到精通(視頻實(shí)戰(zhàn)版)