我有绘制圆圈的功能(canvasCPI和canvasGDP是我的svgs):
var CPIforecircles = canvasCPI.append("g");
var GDPforecircles = canvasGDP.append("g");
function drawGDPForecastCircles(theNum){
GDPforecircles.append("circle")
.attr("r", 3)
.attr("class", "circleGDPFore")
.style("display", null)
.attr("transform", "translate(" + xScaleQuarterly(dataForecast[theNum].date) + "," + yScaleGDP(dataForecast[theNum].GDPforecast) + ")");
}
function drawCPIForecastCircles(theNum){
CPIforecircles.append("circle")
.attr("r", 3)
.attr("class", "circleCPIFore")
.style("display", null)
.attr("transform", "translate(" + xScaleQuarterly(dataForecast[theNum].date) + "," + yScaleCPI(dataForecast[theNum].CPIforecast) + ")");
}
然后通过我的脚本调用此函数来绘制越来越多的圆圈:
function generateCirclesFore(indexNum){
for (var i=indexNum; i<counterFore+1; i++){
drawGDPForecastCircles(i);
drawCPIForecastCircles(i);
}
}
最终我有两个组元素(CPIforecircles和GDPforecircles),标签内有很多圆圈,但我如何选择这些圆圈作为数组,然后将显示样式应用于无(.style(“display”,“none”) “))只对该阵列中的某些圆圈?
答案 0 :(得分:0)
我决定把我的评论作为答案,所以如果没有答案,这不是正式的。另外,我相信答案是准确的。所以,这是:
selectAll(".circleCPIFore")
.filter(function(d) { d.someProp == someCriteria;})
.style("display","none");