如何根据d.Status!==""
d属于数据(sortedFeatures)
feats = cont.selectAll('feats')
.data(sortedFeatures)
.enter()
.append('g')
.attr('transform', function(d, i) {
d['y'] = (fontsize * i);
d['x'] = self.x_scale(d.start);
return 'translate(' + self.x_scale(d.start) + ',' + fontsize * i + ')';
}).attr('type', 'featureGroup');
polygonLastDelivery = feats.append('g');
polygonLastDelivery.append("path")
.attr("class", "point")
.attr("d", d3.svg.symbol().type("cross"))//I don't want to add this symbol if d.Status==="" can I make a function out of this?
.attr("transform", function(d) { return "translate(" + 15 + "," + 22 + ")"; });
那就是我想在新创建的组中添加一个符号" polygonLastDelivery"取决于是否 .data(sortedFeatures)每个都包含一个状态文本或者它是否为空。你怎么解决这个问题?
我尝试了以上上面的白色成功
.attr("d", function(d) { return d3.svg.symbol().type("cross");})
答案 0 :(得分:0)
你可以使用这样的过滤器:
polygonLastDelivery.append("path")
.filter(function(d) { return d.status !== "" })
.attr("class", "point")
.attr("d", d3.svg.symbol().type("cross"))
.attr("transform", function(d) { return "translate(" + 15 + "," + 22 + ")"; });
如果您想根据状态更改符号,也可以使用每个符号:
polygonLastDelivery.each(function(d){
var object = d3.select(this);
var symbol = (d.status !== "") ? 'cross': 'diamond';
object.append("path")
.attr("class", "point")
.attr("d", d3.svg.symbol().type(symbol))
.attr("transform", function(d) { return "translate(" + 15 + "," + 22 + ")"; });
});