[D3] Basic Interactivity with D3 v4
Data visualizations are a lot more interesting when they’re interactive. Whether it’s clicks, roll overs, or drags, it makes things more compelling, and D3 is up to the task. This lesson demonstrates how to implement basic interactions and shows how D3 can do things vanilla CSS can’t.
var scores = [
{ name: 'Alice', score: 96 },
{ name: 'Billy', score: 83 },
{ name: 'Cindy', score: 91 },
{ name: 'David', score: 96 },
{ name: 'Emily', score: 88 }
]; const bars = d3.select('.chart')
.append('svg')
.attr('width', 300)
.attr('height', 300)
.style('background', 'white')
.selectAll('g')
.data(scores)
.enter()
.append('g')
.attr('transform', (d, i) => 'translate(0, ' + i * 33 + ')'); bars.append('rect')
.attr('width', d => d.score)
.attr('class', 'bar')
.on('mouseover', function(d, i, elements) {
// transform the hover item to scale 1.1
d3.select(this).classed('barOn', true); // set not hover elements to opacity 0.8
d3.selectAll(elements)
.filter(':not(:hover)')
.style('opacity', 0.6);
})
.on('mouseout', function(d, i, elements) {
d3.select(this).classed('barOn', false);
d3.selectAll(elements)
.style('opacity', 1);
}); bars.append('text')
.text(d => d.name)
.attr('y', 20)
[D3] Basic Interactivity with D3 v4的更多相关文章
- D3.js 入门学习(二) V4的改动
//d3.scan /* 新的d3.scan方法对数组进行线性扫描,并根据指定的比较函数返回至少一个元素的索引. 这个方法有点类似于d3.min和d3.max. 而d3.scan可以得到极值的索引而不 ...
- D3学习之:D3.js中的12中地图投影方式
特别感谢:1.[张天旭]的D3API汉化说明.已被引用到官方站点: 2.[馒头华华]提供的ourd3js.com上提供的学习系列教程,让我们这些新人起码有了一个方向. 不得不说,学习国外的新技术真的是 ...
- [D3] Drawing path in D3
Here we have a force layout with three nodes. In the example, we will link three nodes with line and ...
- [D3] 11. Basic D3 chart interactivity on(), select(this), classed(class, trueorfalse)
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- [D3] 12. Basic Transitions with D3
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- [D3] Reuse Transitions in D3 v4
D3 transitions start executing as soon as they’re created, and they’re destroyed once they end. This ...
- [D3] Animate Transitions in D3 v4
D3 makes it easy to add meaningful animations to your data visualizations. Whether it’s fading in ne ...
- [D3] Margin Convention with D3 v4
You can’t add axes to a chart if you don’t make room for them. To that end, the D3 community has ado ...
- D3.JS V4 绘制中国地图
参考:http://bl.ocks.org/almccon/fe445f1d6b177fd0946800a48aa59c71 http://blog.csdn.net/lzhlzz/article/d ...
随机推荐
- css3中关于伪类的使用
目标: css中after伪类,last-child伪类的使用.以及部分css3的属性. 过程: 在制作导航时.常常会遇到在每个li后面加入一个切割符号,到最后一个元素的时候,切割符就会去掉的一种效果 ...
- C#运算符小例子
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- php中str_repeat函数
php中str_repeat函数 一.作用 用于repeat str 二.实例:输出菱形 代码: <!DOCTYPE html> <html lang="en"& ...
- c++中重载、重写、覆盖的区别
Overload(重载):在C++程序中,可以将语义.功能相似的几个函数用同一个名字表示,但参数或返回值不同(包括类型.顺序不同),即函数重载.(1)相同的范围(在同一个类中):(2)函数名字相同:( ...
- 56.如何清除已经设置的npm config配置
npm config delete registry npm config delete disturl 或者 npm config edit 找到淘宝那两行,删除
- js---对象 和 函数this
一:对象创建的方法 //普通 字面量形式 var obj = { name:'名字', fn:function(){ console.log(this.name); } } //new 实例 var ...
- 认知 Git 和 GitHub
今天被一个大牛的大哥问了个问题,问住了.原问题是“你是到github吗?git呢?” 我堂而皇之的说,“他们不是同一个吗?” 结果大牛大哥狠狠地回了我一句“百度去”..好吧我乖乖去百度了. 这是我百度 ...
- SSH远程快速登录Linux
SSH远程快速登录Linux 使用SSH管理linux服务器,通常要使用ssh,然后输入用户,密码,其实只要配置一个文件就可以方便登录.假设要登录server域名是www.interne ...
- 游标 scroll
scroll表示可随意移动游标指针(否则只能向前)
- JavaScript--数据结构与算法之链表实现约瑟夫环
传说在公元1 世纪的犹太战争中,犹太历史学家弗拉维奥·约瑟夫斯和他的40 个同胞被罗马士兵包围.犹太士兵决定宁可自杀也不做俘虏,于是商量出了一个自杀方案.他们围成一个圈,从一个人开始,数到第三个人时将 ...