Sto sperimentando l'utilizzo di più nomi di classi per gli elementi SVG in modo che (si spera) potrei selezionare un sottoinsieme di essi utilizzando selectAll e "parts" del nome della classe. Purtroppo nulla di ciò che ho provato funziona e non ho trovato un esempio online. Il codice seguente mostra cosa sto cercando di fare con un semplice esempio di quattro cerchi. Due cerchi hanno il nome di classe "mYc 101" e due cerchi hanno il nome di classe "mYc 202". selectAll (". mYc") dà tutti e quattro i cerchi. Cosa succede se voglio solo le cerchie con il nome di classe "mYc 101"? Può essere fatto? Come? Grazie infinite!Come utilizzare D3 selectAll con più nomi di classe
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<div id="my_div"></div>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var m_div = d3.select("#my_div");
var m_svg = m_div.append("svg");
var g = m_svg.append("g");
g.append("circle")
.attr("class", "mYc 101")
.attr("cx", 100)
.attr("cy", 100)
.attr("r", 50)
.attr("style", "stroke: green; stroke-width: 8; fill: #000000");
g.append("circle")
.attr("class", "mYc 101")
.attr("cx", 300)
.attr("cy", 100)
.attr("r", 50)
.attr("style", "stroke: green; stroke-width: 8; fill: #000000");
g.append("circle")
.attr("class", "mYc 202")
.attr("cx", 100)
.attr("cy", 300)
.attr("r", 50)
.attr("style", "stroke: blue; stroke-width: 8; fill: #000000");
g.append("circle")
.attr("class", "mYc 202")
.attr("cx", 300)
.attr("cy", 300)
.attr("r", 50)
.attr("style", "stroke: blue; stroke-width: 8; fill: #000000");
// This selects all four circles
var list = d3.selectAll(".mYc");
// But if I want to select only class "mYc 101", none of these work.
// In fact they all give an error.
// var list1 = d3.selectAll(".mYc 101");
// var list1 = d3.selectAll(".mYc .101");
// var list1 = d3.selectAll(".mYc.101");
// var list1 = d3.selectAll(".mYc,.101");
// var list1 = d3.selectAll(".101");
</script>
</body>
Grazie mille Lars !! La chiave era il fatto che i nomi delle classi non possono iniziare con un numero. Bill –