显示/隐藏d3.js中的图层 [英] show/hide layers in d3.js

查看:1141
本文介绍了显示/隐藏d3.js中的图层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先:我是新的d3.js!

First of all: I'm new to d3.js!

我有一张地图和一些点显示在它上面。现在我想添加按钮来显示/隐藏点。
到目前为止:

I have a map and some points displayed on it. Now I want to add buttons to show/hide the points. What I have until now:

function checkAll(){
    d3.selectAll("g").attr("visibility", "visible");
}
function uncheckAll(){
    d3.selectAll("g").attr("visibility", "hidden");
}

到目前为止只是隐藏/显示整个地图。

This works so far but hides/shows the whole map.

我有一个函数drawpoints()在地图上绘制点。
如何更改我的代码只显示/隐藏点而不是整个地图?

I have a function "drawpoints()" that draws the points on the map. How can I change my code that it only shows/hides the points and not the whole map?

推荐答案

将需要仅选择您要隐藏的元素。例如,如果它们由类标识,您将执行以下操作:

You would need to select only the elements that you want to hide. If, for example, they are identified by a class, you would do the following:

d3.selectAll(".classOfCircles").attr("visibility", "hidden");

这篇关于显示/隐藏d3.js中的图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆