【问题标题】:Filtering in JavaScript with radio button using D3 library使用 D3 库过滤带有单选按钮的 JavaScript
【发布时间】:2014-07-07 12:20:50
【问题描述】:

我正在尝试使用一组单选按钮来过滤 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

【问题讨论】:

  • 那么...你有什么问题?
  • 对不起。我的问题是如何使用单选按钮控制数据过滤?
  • 您可以将处理函数附加到相应更改数据集的单选按钮。

标签: javascript d3.js radio-button scatter-plot input-filtering


【解决方案1】:

我解决了,这是我的代码:

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"; })
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-24
    • 1970-01-01
    • 2022-11-08
    • 2020-08-30
    • 1970-01-01
    • 2019-01-02
    • 2016-07-11
    相关资源
    最近更新 更多