D3:如何在数据绑定期间验证数据
D3: How to validate data during data binding?
我正在尝试渲染甘特图,其中我将数据绑定在 d3 中并在两端渲染圆圈。我的数据与此结构有些相似:
function Event(start, end) {
this.startTime = start;
this.endTime = end;
}
我像往常一样绑定我的数据:
myplot.selectAll(".EventStart")
.data(EventList).enter()
.append("circle")
.attr("class", "EventStart")
.attr("cx", function (d) { return scaleX(d.startTime)})
.attr("cy", function (d) { return eventRenderingHeight })
.attr("r", 5)
.style("fill", "white");
myplot.selectAll(".EventEnd")
.data(EventList).enter()
.append("circle")
.attr("class", "EventEnd")
.attr("cx", function (d) { return scaleX(d.endTime)})
.attr("cy", function (d) { return eventRenderingHeight })
.attr("r", 5)
.style("fill", "white");
现在,这将在我的事件的开始和结束时呈现两个白色圆圈。但是如果开始时间和结束时间相同,我想省略渲染第二个圆圈。我该怎么做?
谢谢。
您可以在绑定之前过滤dataList
myplot.selectAll(".EventEnd")
.data(EventList.filter(function(d){ return d.startTime!=d.endTime }))
.enter()
.append("circle")
.attr("class", "EventEnd")
.attr("cx", function (d) { return scaleX(d.endTime)})
.attr("cy", function (d) { return eventRenderingHeight })
.attr("r", 5)
.style("fill", "white");
或
过滤器如下所示。
myplot.selectAll(".EventEnd")
.data(EventList)
.enter()
.append("circle")
.filter(function(d) { return d.startTime!=d.endTime })
.attr("class", "EventEnd")
.attr("cx", function (d) { return scaleX(d.endTime)})
.attr("cy", function (d) { return eventRenderingHeight })
.attr("r", 5)
.style("fill", "white");
相关文章:
- 使用html中的外部javascript进行数据验证
- JS验证ajax返回的html中的表单数据
- 自定义验证并格式化从数据数据库返回的响应-BEGINNER
- 如何在使用ajax提交的codeigniter中使用form_validation验证表单数据
- 正则表达式(JavaScript),用于创建数字必须大于x的数据验证
- 验证数据并将其保存到数据库以供实时应用程序使用的正确方法
- 模态窗口yii2中的Ajax验证数据
- 来自第三方身份验证的 Firebase 身份验证数据在移动 safari iOS8 中始终为空
- 验证数据是否已在数据库中,具有更多输入相同的类
- 验证数据 jQuery Handsontable 输入
- D3:如何在数据绑定期间验证数据
- Validation jQuery未正确验证数据
- 如何在Azure移动服务中使用使用逻辑验证数据
- 表单验证——jQuery验证是否足够,以及如何在PHP中巧妙地验证数据
- 向firebase数据库添加身份验证数据
- 单击按钮,我想验证数据,如果为真,我想要删除确认对话框.这可能吗?
- web和jvm之间的Firebase身份验证数据不匹配
- Jquery验证数据
- 如何通过编辑时验证数据是否相同来更改按钮文本
- 使用JS Regex验证数据