Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在d3中的div中选择svg?_Javascript_D3.js_Svg - Fatal编程技术网

Javascript 如何在d3中的div中选择svg?

Javascript 如何在d3中的div中选择svg?,javascript,d3.js,svg,Javascript,D3.js,Svg,我在一个div中添加了一个SVG。下面是代码: var metricDiv = d3.select("#metric4"); var metricSVG = metricDiv.append("svg") .attr("width", width) .attr("height", height) .attr("id", "metricmap") .call(zoom) .append("g"); //create a place holder rectan

我在一个div中添加了一个SVG。下面是代码:

var metricDiv = d3.select("#metric4");
var metricSVG = metricDiv.append("svg")
    .attr("width", width)
    .attr("height", height)
    .attr("id", "metricmap")
    .call(zoom)
    .append("g");
//create a place holder rectangle to keep floats inline
var svgContainer = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", width)
    .attr("id", "placeholder");
d3.json("img/defense_data.json", function (error, map) {
    if (error) return console.error(error);
    var projection = d3.geo.mercator()
        .center([7.612337603149424, 51.96211781909236])
        .scale(3000000);
    //.translate(0,0);
    var path = d3.geo.path()
        .projection(projection);
    metricSVG.selectAll(".city_block_landmarks")
        .data(topojson.feature(map, map.objects.city_block_landmarks).features)
        .enter().append("path")
        .attr("class", function (d) {
            //console.log(d.properties.class)
            return d.properties.classfeature;
        })
        .attr("id", function (d) {
            //console.log(d.id)
            return d.id;
        })
        .attr("d", path);
    metricSVG.selectAll(".hidden_landmarks")
        .data(topojson.feature(map, map.objects.hidden_landmarks).features)
        .enter().append("path")
        .attr("class", function (d) {
            //console.log(d.properties.class)
            return d.properties.classfeature;
        })
        .attr("id", function (d) {
            //console.log(d.id)
            return d.id;
        })
        .attr("d", path);
    metricSVG.selectAll(".botanica_mid_polygons")
        .data(topojson.feature(map, map.objects.botanica_mid_polygons).features)
        .enter().append("path")
        .attr("class", function (d) {
            //console.log(d.properties.class)
            return d.properties.classfeature;
        })
        .attr("id", function (d) {
            //console.log(d.id)
            return d.id;
        })
        .attr("d", path);
    metricSVG.selectAll(".streets_linear_features")
        .data(topojson.feature(map, map.objects.streets_linear_features).features)
        .enter().append("path")
        .attr("class", function (d) {
            //console.log(d.properties.class)
            return d.properties.classfeature;
        })
        .attr("id", function (d) {
            //console.log(d.id)
            return d.id;
        })
        .attr("d", path);
});

现在,我想选择附加在div metric4中的所有内容,而不是div本身。我知道我们通常使用d3.select函数来实现这一点,但我不知道在选择函数的括号内写什么来选择附加到div中的所有内容。有人能帮我解决这个问题吗?

如果要选择元素中的所有内容,可以使用*作为选择器

d3.selectmetric4.selectAll*

这将从该div中选择所有内容,您可以继续使用d3方法链接来完成您想要的选择