NoteZ_技术博客 NoteZ_技术博客
🏠 首页
  • 📚 Web技术
  • 📋 Npm笔记
  • 📑 Markdown
  • 📄 Git笔记
  • 📝 Nginx文档
  • 📓 Linux文档
  • 📖 技术文档
  • 📜 其他文档
  • 🧊 NodeJs
  • 🎡 Express
  • 🔥 Rust
  • 🎉 Koa2
  • 🍃 MongoDB
  • 🐬 MySql
  • 🥦 Oracle
  • 🍁 Python
  • 🍄 JavaScript
  • 🌰 CSS
  • 🧄 HTML
  • 🥑 Canvas
  • 🌽 Nuxt
  • 🍆 React
  • 🥜 Vue
  • 🧅 TypeScript
  • 🌶️ AI
  • 📘 分类
  • 📗 标签
  • 📙 归档
⚜️ 在线编辑 (opens new window)
  • 📁 站点收藏
  • 📦 前端组件库
  • 📊 数据可视化
  • 🌈 开源插件
  • 🎗️ 关于我
  • 🔗 友情链接
GitHub (opens new window)

NoteZ_技术博客

前端界的小学生
🏠 首页
  • 📚 Web技术
  • 📋 Npm笔记
  • 📑 Markdown
  • 📄 Git笔记
  • 📝 Nginx文档
  • 📓 Linux文档
  • 📖 技术文档
  • 📜 其他文档
  • 🧊 NodeJs
  • 🎡 Express
  • 🔥 Rust
  • 🎉 Koa2
  • 🍃 MongoDB
  • 🐬 MySql
  • 🥦 Oracle
  • 🍁 Python
  • 🍄 JavaScript
  • 🌰 CSS
  • 🧄 HTML
  • 🥑 Canvas
  • 🌽 Nuxt
  • 🍆 React
  • 🥜 Vue
  • 🧅 TypeScript
  • 🌶️ AI
  • 📘 分类
  • 📗 标签
  • 📙 归档
⚜️ 在线编辑 (opens new window)
  • 📁 站点收藏
  • 📦 前端组件库
  • 📊 数据可视化
  • 🌈 开源插件
  • 🎗️ 关于我
  • 🔗 友情链接
GitHub (opens new window)
  • Web技术

  • Git笔记

  • Linux文档

  • Markdown

  • Nginx文档

  • Npm笔记

  • 技术文档

  • 其他文档

    • 解决 bash_wget 未找到命令的解决办法
    • CentOS7 常见问题应对,如何升级make和gcc版本
    • CodeMirror代码编辑器实现自定义提示功能增强版(支持搜索、调用接口查询提示内容)
    • CSS 滚动条样式
    • d3 svg 基本图形绘制
      • 1. 路径
      • 2. 折线
      • 3. 多边形
      • 4. 直线
      • 5. 椭圆
    • d3.js中update,enter,exit的概念
    • dat.gui 基本使用方法
    • echarts 使用案例(demo)
    • jsplumb 中文基础教程
    • Linux服务器(centos7)使用LibreOffice将Word转换PDF文档出现中文乱码或方格解决方法
    • npm install 报错 npm ERR code UNABLE_TO_VERIFY_LEAF_SIGNATURE npm ERR errno UNABLE_TO_VERIFY_LEA 解决
    • Npm 清除缓存
    • Npm设置淘宝镜像
    • NPS内网穿透安装方法
    • ThreeJs 基础入门
    • unable to verify the first certificate 原因及解决方法
    • vue 安装node-sass报错解决方案(缺少python2.7支持)
    • windows下安装 stable-diffusion-webui 步骤
    • yarn的安装与使用
    • 关于微信支付 WeixinJSBridge.invoke 、 wx.chooseWXPay使用方法
    • 内网穿透的几款工具汇总
    • 前端使用 swd-deploy 自动化部署项目到服务器
    • 常用工具集(utils.js)
    • 开源项目大杂烩
    • 微信小程序-APP生命周期与运行机制总结
    • 微信小程序踩坑之布局适配单位(rpx、px、vw、vh)
    • 服务器常用的状态码
    • 解决google浏览器翻译无法使用的问题
    • 解决使用 Gitalk 登录授权报错的问题
    • 解决在使用 stable-diffusion-webui 时,安装 gfpgan 失败的方案(windows下的操作)
    • 通过 js 进行 shapefile 文件解析渲染方法
    • 部署脚本 deploy.sh
    • Tauri打包慢或者报错问题解决方法
    • Ubuntu和Nginx搭配Certbot配置SSL证书https访问网站
    • Centos下yum无法正常使用
    • Linux 系统下通过 Let‘s Encrypt 生成免费 https 证书的步骤
    • Mongo 风格的查询对象映射到 SQL 查询的 Node.js 库 json-sql
    • CentOS7安装与卸载anaconda3基础步骤
  • 前端开发
  • 其他文档
NoteZ
2022-05-29
目录

d3 svg 基本图形绘制

# 1. 路径

// 在 body 中插入一個 svg
var svg = d3.select('body').append('svg');
 
// 在 svg 中插入一個 path
svg.append('path').attr({
    d: 'M50 150Q300 50 300 150T450 150'
}).style({
    fill: 'none', 
    stroke: 'purple',
    'stroke-width': 5
});
1
2
3
4
5
6
7
8
9
10
11

# 2. 折线

// 在 body 中插入一個 svg
var svg = d3.select('body').append('svg');
 
 
// 在 svg 中插入 polyline
svg.append('polyline').attr({
    points: '100,10 40,180 190,60 10,60 160,180 100,10'
}).style({
    fill: 'black', 
    stroke: 'green',
    'stroke-width': 4
});
 
// 在 svg 中插入 polyline
svg.append('polyline').attr({
    points: '200,160 240,160 240,120 280,120 280,80 320,80 320,40 360,40 360,160 240,160'
}).style({
    fill: 'none', 
    stroke: 'green',
    'stroke-width': 4
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# 3. 多边形

// 在 body 中插入一個 svg
var svg = d3.select('body').append('svg');
// 在 svg 中插入 polygon
svg.append('polygon').attr({
    points: '50,10 20,50 80,50'
}).style({
    fill: 'none', 
    stroke: '#f0f',
    'stroke-width': 4
});
 
// 在 svg 中插入 polygon
svg.append('polygon').attr({
    points: '70,10 130,10 100,50 '
}).style({
    fill: 'none', 
    stroke: '#520',
    'stroke-width': 4
});
 
// 在 svg 中插入 polygon
svg.append('polygon').attr({
    points: '150,10 120,50 180,50'
}).style({
    fill: 'none', 
    stroke: '#f0f',
    'stroke-width': 4
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

# 4. 直线

// 在 body 中插入一個 svg
var svg = d3.select('body').append('svg');
 
// 在 svg 中插入 line
svg.append('line').attr({
    x1: 40,
    y1: 70,
    x2: 250,
    y2: 70
}).style({
    stroke: 'black',
    'stroke-width': 5
});
 
// 在 svg 中插入 line
svg.append('line').attr({
    x1: 40,
    y1: 140,
    x2: 250,
    y2: 140
}).style({
    stroke: 'black',
    'stroke-width': 5
});
 
// 在 svg 中插入 line
svg.append('line').attr({
    x1: 100,
    y1: 10,
    x2: 100,
    y2: 200
}).style({
    stroke: 'black',
    'stroke-width': 5
});
 
// 在 svg 中插入 line
svg.append('line').attr({
    x1: 180,
    y1: 10,
    x2: 180,
    y2: 200
}).style({
    stroke: 'black',
    'stroke-width': 5
});
 
// 在 svg 中插入 circle
svg.append('circle').attr({
    cx: 140,
    cy: 105,
    r: 20
}).style({
    fill: 'none',
    stroke: 'red',
    'stroke-width': 4
});
 
// 在 svg 中插入 line
svg.append('line').attr({
    x1: 50,
    y1: 20,
    x2: 80,
    y2: 50
}).style({
    stroke: 'black',
    'stroke-width': 5
});
 
// 在 svg 中插入 line
svg.append('line').attr({
    x1: 80,
    y1: 20,
    x2: 50,
    y2: 50
}).style({
    stroke: 'black',
    'stroke-width': 5
});
 
// 在 svg 中插入 circle
svg.append('circle').attr({
    cx: 220,
    cy: 180,
    r: 20
}).style({
    fill: 'none',
    stroke: 'red',
    'stroke-width': 4
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

# 5. 椭圆

// 在 body 中插入一個 svg
var svg = d3.select('body').append('svg');
 
    // 在 svg 中插入 ellipse
svg.append('ellipse').attr({
    cx: 100,
    cy: 60, 
    rx: 30, 
    ry: 50
}).style({
    fill: 'pink', 
    stroke: 'green', 
    'stroke-width': 10
});
 
// 在 svg 中插入 ellipse
svg.append('ellipse').attr({
    cx: 200,
    cy: 60, 
    rx: 30, 
    ry: 50
}).style({
    fill: 'pink', 
    stroke: 'green', 
    'stroke-width': 10,
    'fill-opacity': .6
});
 
// 在 svg 中插入 ellipse
svg.append('ellipse').attr({
    cx: 145,
    cy: 180, 
    rx: 110, 
    ry: 40
}).style({
    fill: 'pink', 
    stroke: 'green', 
    'stroke-width': 5,
    opacity: .6
});

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#SVG
上次更新: 2024/01/30, 00:35:17
CSS 滚动条样式
d3.js中update,enter,exit的概念

← CSS 滚动条样式 d3.js中update,enter,exit的概念→

最近更新
01
Gitea数据备份与还原
03-10
02
Linux 中使用 rsync 同步文件目录教程
03-10
03
Linux 使用 rsync 互相传输同步文件的简单步骤
03-08
更多文章>
Theme by Vdoing | Copyright © 2019-2025 NoteZ,All rights reserved | 冀ICP备2021027292号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式