[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 ...
随机推荐
- hdoj 1159 Common Subsequence【LCS】【DP】
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 转:IOS推送代码
实例:调用方法:- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary ...
- 改动GDAL库支持RPC像方改正模型
近期在做基于RPC的像方改正模型.方便对数据进行測试,改动了GDAL库中的RPC纠正模型,使之能够支持RPC像方改正參数. 以下是RPC模型的公式,rn,cn为归一化之后的图像行列号坐标,PLH为归一 ...
- JavaWeb-04(BOM&DOM)
JavaWeb-04 JavaWeb-BOM&DOM BOM 一.知识回想 * BOM 概述 * BOM 的各个对象 * window对象 innerHeight,innerWidth doc ...
- js---03属性操作
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- [ Java ] [ Spring ] [ Spring MVC ] Tutorial
中文 Spring 教學 http://hatemegalaxy.blogspot.tw/2014/09/spring-framework-useful-tutorials-for.html 英文 S ...
- 设置https验证方式
if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
- 原生js中获取this与鼠标对象以及vue中默认的鼠标对象参数
1.通过原生js获取this对象 <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...
- Markdown最简单常用的语法
1,文本强调: 文本倾斜,*我是倾斜的文本* 文本加粗,**我是加粗的文本** 文本删除线,~~带删除线的文本~~ 2,链接,分为行内式与参数式,参数式多用于在文章中多次使用相同的链接 行内式写法:[ ...
- golang-小试牛刀
首先说下,我为什么选择go吧.之前一直做的都是.net平台下的开发,常用的服务端语言就是C#.刚接触C#的时候,就喜欢上了这种高级语言,它优雅.易上手.开发周期短,很多高级特性以及自带的托管内存管理G ...