[英]Filtering in JavaScript with radio button using D3 library
我正在嘗試使用一組單選按鈕在 D3 散點圖上的數據之間進行過濾。 我的散點圖基於http://bl.ocks.org/mbostock/4063663 。 我只修改了代碼以滿足我的數據需求。 鏈接中的代碼與我所擁有的非常接近。
我的 CSV 文件中的代碼按以下方式排列。
DataType1,DataType2,DataType3,DataType4,
1,2,3,4
1,2,3,4
1,2,3,4
1,2,3,4
1,2,3,4
我解決了,這是我的代碼:
Open<input type="radio" name="Status" id="radio-open" value="Open" onClick="window.location.reload()" />
Closed<input type="radio" name="Status" id="radio-closed" value="Closed" onClick="window.location.reload()"/>
Clear<input type="radio" name="Status" id="radio-clear" value="Clear" onClick="window.location.reload()"/>
和:
if (!document.getElementById('radio-clear').checked) {
if (document.getElementById('radio-open').checked) {
data = data.filter(function(d) { return d["Status"] == "Open"; })
}
else if (document.getElementById('radio-closed').checked) {
data = data.filter(function(d) { return d["Status"] == "Closed"; })
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.