SVG is a great output format for data visualizations because of its scalability, but it comes with some idiosyncrasies and unique challenges. In this lesson we’ll learn how to use graphics containers, the SVG equivalent of a div, as well as text elements for displaying, you guessed it, text.

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') // 'g' works as canvas on svg
.data(scores)
.enter()
.append('g')
.attr('transform', (d, i) => 'translate(0, ' + i * 33 + ')'); bars.append('rect')
.attr('width', d => d.score)
.attr('class', 'bar'); bars.append('text')
.text(d => d.name)
.attr('y', 20);

[D3] SVG Graphics Containers and Text Elements in D3 v4的更多相关文章

  1. D3+svg 案例

    <!doctype html><html lang="en"><head> <meta charset="UTF-8" ...

  2. Java基础之扩展GUI——使用对话框创建文本元素(Sketcher 4 creating text elements)

    控制台程序. 为了与Sketcher中的其他元素类型保持一致,需要为Elements菜单添加Text菜单项和工具栏按钮.还需要定义用来表示文本元素的类Element.Text. 1.修改Sketche ...

  3. [D3] Create DOM Elements with D3 v4

    Change is good, but creating from scratch is even better. This lesson shows you how to create DOM el ...

  4. d3.svg.line()错误:TypeError: d3.svg.line is not a function

    var line_generator= d3.svg.line() .x(function (d,i) { return i; }) .y(function (d) { return d; }) 错误 ...

  5. [D3] Select DOM Elements with D3 v4

    Before you can create dazzling data driven documents, you need to know how D3 accesses the DOM. This ...

  6. html5 svg 第八章 文字text

    虽然它可能是真实的,每一个画面讲述了一个故事,这是完全正确的,用言语来帮助讲故事.因此,SVG有几个元素,让你将文本添加到您的图形. 文本术语 Text Terminology 在我们调查的主要方法添 ...

  7. [D3] Modify DOM Elements with D3 v4

    Once you can get hold of DOM elements you’re ready to start changing them. Whether it’s changing col ...

  8. d3 svg简单学习

    矩形 <rect x="/> 圆形 <circle cx="/> 椭圆 <ellipse cx="/> 线 <line x1=& ...

  9. Text Elements(文本元素)对象

    1.T-Code:SE32 操作路径:主菜单——转到——内文元素——选择内文 2. 清单标题(List heading) 用于定义Report标题名称及描述,如图: 2. 選擇內文 (Selectio ...

随机推荐

  1. [Python] Manipulate Data with Dictionaries in Python

    Dictionaries may be familiar to you as hash maps. In this lesson, you will learn how to create them, ...

  2. Linux下Oracle的sqlplus中上下左右退格键无法使用

    一.配置yum源并安装readline* 配置本地yum 1.挂载光盘 mount /dev/cdrom /mnt/media 2,新建本地yun源的配置文件 vi /etc/yum.repos.d/ ...

  3. 最小生成树-并查集-Kruskal-zoj-2048-special judge

    Highways description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has a ...

  4. MySql 存储引擎的选取

    存储引擎是为不同的表类型处理 SQL 操作的 MySql 组件.InnoDB 是默认的.最通用的存储引擎,也是官方推荐使用的存储引擎,除非一些特定案例.MySql 5.6 中的 CREATE TABL ...

  5. 62.C++文件操作list实现内存检索,实现两千万数据秒查

    1 #include <iostream> #include <fstream> #include <cstdlib> #include <string> ...

  6. linux的vi或vim文件时,怎样消除刚才查找字符串的高亮?

    有时候,自己在通过/查找字符串时,会出现: 但是呢,当你保存,再次进入还是会出现这么花的高亮显示,很令人苦恼. 解决办法 随便,输入没有的字符串,即可解决. 如下 /sssssssssssssssss ...

  7. 完整性检查工具Nabou

    完整性检查工具Nabou 650) this.width=650;" onclick="window.open("http://blog.51cto.com/viewpi ...

  8. fetch 封装

    fetch.js var http = { get: function (url) { return new Promise((resolve, reject) => { fetch(url) ...

  9. Javascript和jquery事件--事件冒泡和事件捕获

    jQuery 是一个 JavaScript 库,jQuery 极大地简化了 JavaScript 编程,在有关jq的描述中,jq是兼容现有的主流浏览器,比如谷歌.火狐,safari等(当然是指较新的版 ...

  10. POJ 2828 线段树单点更新 离线搞

    Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...