Reputation: 968
I am working on a scatter plot where I want to use "cross" symbol in d3 just for a particular key in my case "Positive Control" and skip cross symbol for drawing other shapes in the chart. I was able to plot "+" just for particular key using if condition but I am not able to figure out how to skip "cross" symbol getting plotted for rest of the keys in the data set. See the what I have so far on this link. I want to change the d3.symbol function to use "+" symbol only once. Thank you for your help in advance.
series.selectAll("g.point")
.data(function(d) { return d.values;})
.enter()
.append("svg:path")
.attr("class",function(d,i) {return (d.x).replace(/\s/g, ''); }) // removing spaces
.attr("transform", function(d,i) { return "translate(" + x(d.y) + "," + y(d.z) + ")"; })
.attr("d", function(d,i,j) {
if(d.Call === "someCall") {
return d3.svg.symbol().type('cross')();
}
else {
return d3.svg.symbol().type(d3.svg.symbolTypes[j])(); // remove "+" symbol from the d3.symbol function for all other keys - use some other symbol instead
}
})
.style("fill", function(d) { return color(d.Call); });
[![enter image description here][2]][2]
Upvotes: 1
Views: 937
Reputation: 14063
You could just specify the symbol array explicitly and omit the cross
var mySymbols = ["circle", "diamond", "square", "triangle-down", "triangle-up"];
return d3.svg.symbol().type(mySymbols[j%mySymbols.length])();
Upvotes: 1