可视化:svg相关基础
01.svg的嵌入.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="author" content="李可">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>svg的嵌入方式</title>
</head>
<body>
<h1>svg的6种嵌入方式</h1>
<!-- svg、图片、背景、iframe、object、embed 、-->
<!-- 直接写svg -->
<svg width="200" height="200" viewBox="0 0 200 200" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<circle cx="100" cy="100" r="20" fill="red" />
</svg>
<!-- img -->
<img src="svg.svg" alt="">
<!-- background -->
<div style="width:200px;height:200px;display:inline-block;background-image:url('svg.svg')"></div>
<!-- iframe -->
<iframe src="svg.svg"></iframe>
<!-- embed pluginspage下插件-->
<embed src="svg.svg" width="200" height="200" type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/"/>
<!-- object codebase下插件-->
<object data="svg.svg" width="200" height="200" type="image/svg+xml" codebase="http://www.adobe.com/svg/viewer/install/"/>
</body>
</html>
运行
02.svg基本图形.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="author" content="李可">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>6种基本图形</title>
</head>
<body>
<!-- 起点 终点 对应的x,y像定位后的left top值-->
<!-- 6种基本图形line, rect, ellipse, circle, polyline, polygon-->
<!-- points'空格'或者'逗号' 像path(路径)/polyline(折线)/polygon(多边形)都用到多点(points)-->
<!-- 折线 不闭合。多边形闭合-->
<svg width="1000" height="1000" viewBox="0 0 1000 1000" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- 线 起点 终点 -->
<line x1="0" y1="0" x2="100" y2="100" stroke="black" stroke-width="2"/>
<!-- 矩形 起点(左上角) 宽高 -->
<rect x="100" y="0" width="150" height="100"/>
<!-- 圆 中心点 半径 -->
<circle cx="300" cy="50" r="50" />
<!-- 椭圆 中心点 x y半径-->
<ellipse cx="425" cy="50" rx="75" ry="50"/>
<!-- 折线 多个点(逗号或者空格) -->
<!-- 多条线连接起来角,没有棱角 -->
<polyline points="500 0 600 50 550 100" fill='none' stroke="black" stroke-width="20"/>
<line x1="500" y1="100" x2="600" y2="150" stroke="black" stroke-width="20"/>
<line x1="600" y1="150" x2="550" y2="200" stroke="black" stroke-width="20"/>
<!-- (首尾闭合的折线) 多边形 多点(逗号或者空格) -->
<polygon points="600,0,700,50,650,100" fill='none' stroke="black" stroke-width="2"/>
</svg>
</body>
</html>
运行
03.svg基本样式.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="author" content="李可">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>基本样式</title>
</head>
<body>
<!--
位置(x,y,r)的属性不能写到style里面,其余可以
width height rect拥有这样的属性
fill="red" 默认填充黑色色(常用transparent,none)
stroke="black" 边框色
stroke-width="2" 边框宽
-->
<!--拿circle举例子-->
<svg width="1000" height="1000" viewBox="0 0 1000 1000" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- 圆 中心点 半径 -->
<circle cx="50" cy="50" r="50" fill="red" stroke="black" stroke-width="2"/>
<circle cx="50" cy="150" r="50" style="fill:transparent; stroke:black; stroke-width:2;"/>
</svg>
</body>
</html>
运行
04.svg用js操作.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="author" content="李可">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>js操作svg</title>
</head>
<body>
<script>
let getTag = (name, attrs) => {
let svg = document.createElementNS('http://www.w3.org/2000/svg', name);
for (var attr in attrs) {
//这里全部使用属性,并没有使用样式
svg.setAttribute(attr, attrs[attr])
}
return svg;
}
let svg = getTag('svg', { xmlns: 'http://www.w3.org/2000/svg', 'xmlns:xlink': "http://www.w3.org/1999/xlink", version: "1.1", width: '100%', height: '100%', viewBox: "0 0 1000 1000", });
document.querySelector('body').appendChild(svg);
let line = getTag('line', { x1: 0, y1: 0, x2: 100, y2: 100, stroke: 'green', 'stroke-width': 5 });
document.querySelector('svg').appendChild(line);
let rect = getTag('rect', { x: 100, y: 0,width: 150, height: 100, fill: 'none',stroke: 'green', 'stroke-width': 5 });
document.querySelector('svg').appendChild(rect);
let circle = getTag('circle', { cx:"300", cy:"50", r:"50" ,fill: 'none',stroke: 'green', 'stroke-width': 5 });
document.querySelector('svg').appendChild(circle);
let ellipse = getTag('ellipse', { cx:"425", cy:"50" ,rx:"75" ,ry:"50", fill: 'none',stroke: 'green', 'stroke-width': 5 });
document.querySelector('svg').appendChild(ellipse);
let polyline = getTag('polyline', { points:"500 0 600 50 550 100", fill: 'none',stroke: 'green', 'stroke-width': 5 });
document.querySelector('svg').appendChild(polyline);
let polygon = getTag('polygon', { points:"600,0,700,50,650,100", fill: 'none',stroke: 'green', 'stroke-width': 5 });
document.querySelector('svg').appendChild(polygon);
111
</script>
</body>
</html>
运行
05.svg结构标签g.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="author" content="李可">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>js操作svg</title>
</head>
<body>
<svg width="1000" height="1000">
<!-- 圆 中心点 半径 -->
<circle cx="100" cy="100" r="50" fill="none" stroke="black" stroke-width="2" />
<circle cx="100" cy="100" r="60" fill="none" stroke="black" stroke-width="2" />
<circle cx="100" cy="100" r="70" fill="none" stroke="black" stroke-width="2" />
<!--
将公用的属性抽离出来赋值给g标签
但是: 标签特有的放到g标签上不起作用。
比如circle的 cx cy r line的x1
g标签内全部是circle也不能抽离cx cy r等
-->
<g stroke="black" stroke-width="2" fill="none">
<circle cx="300" cy="100" r="50" />
<circle cx="300" cy="100" r="60" />
<circle cx="300" cy="100" r="70" />
<line x1="300" y1="100" x2="400" y2="200" />
</g>
<!--
但是这些不能抽离的属性大部分是跟位置有关
使用transform变换来代替
-->
<g transform="translate(600,100)"stroke="black" stroke-width="2" fill="none">
<circle r="50" />
<circle r="60" />
<circle r="70" />
<line x1="300" y1="100" x2="400" y2="200" />
</g>
<!--
这时line是基于transform之后的距离再移动
-->
<g transform="translate(800,100)"stroke="black" stroke-width="2" fill="none">
<circle r="50" />
<circle r="60" />
<circle r="70" />
<line x1="0" y1="0" x2="100" y2="0" />
</g>
</svg>
</body>
</html>
运行
可视化:svg相关基础的更多相关文章
- 数据可视化-svg入门基础(二)
接上一篇:数据可视化-svg入门基础(一),基础一主要是介绍了svg概念,元素样式设置等. svg是(scalable vector graphic)伸缩矢量图像. 一.目录 (1)图形元素 (2)文 ...
- SVG相关学习(一)SVG基础
SVG 相关学习 SVG SVG 指可伸缩矢量图形 (Scalable Vector Graphics) SVG viewBox <svg width="500" heigh ...
- iOS蓝牙开发(二)蓝牙相关基础知识
原文链接: http://liuyanwei.jumppo.com/2015/07/17/ios-BLE-1.html iOS蓝牙开发(一)蓝牙相关基础知识: 蓝牙常见名称和缩写 MFI ====== ...
- Linux 相关基础笔记
html,body { } .CodeMirror { height: auto } .CodeMirror-scroll { } .CodeMirror-lines { padding: 4px 0 ...
- linux设备驱动归纳总结(二):模块的相关基础概念【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-59415.html linux设备驱动归纳总结(二):模块的相关基础概念 系统平台:Ubuntu 10 ...
- linux设备驱动归纳总结(一)内核的相关基础概念【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-59413.html linux设备驱动归纳总结(一):内核的相关基础概念 xxxxxxxxxxxxxx ...
- 深入理解mysql之BDB系列(1)---BDB相关基础知识
深入理解mysql之BDB系列(1) ---BDB相关基础知识 作者:杨万富 一:BDB体系结构 1.1.BDB体系结构 BDB总体的体系结构如图1.1所看到的,包括五个子系统(见图1.1 ...
- SVG的基础使用
SVG的基础使用: <%@ page language="java" contentType="text/html; charset=UTF-8" pag ...
- 【RAC】RAC相关基础知识
[RAC]RAC相关基础知识 1.CRS简介 从Oracle 10G开始,oracle引进一套完整的集群管理解决方案—-Cluster-Ready Services,它包括集群连通性.消息和锁. ...
随机推荐
- Docker系列二:Docker的基本结构
Docker的基本结构 Docker 的三大基础组件 Docker有三个重要的概念:仓库 , 镜像 和 容器 ,它们是Docker的三大基出组件 Docker的组织结构 Docker处于操作系统和虚拟 ...
- http缓存(http caching)
通过使用缓存web网站和web应用的性能能够得到显著的提升.Web caches能够减小延迟和网络流量,从而缩短展示资源所花费的时间. 在http中控制缓存行为的首部字段是Cache-Control, ...
- mongodb命令行group分组和java代码中group分组
group分组统计是数据库比较常用的功能,mongodb也不例外.不过相对于普通的增删改查,group操作就略微麻烦一些, 这里对group在shell中的操作.使用java原生代码操作以及集成spr ...
- mysql常用基础操作语法(三)~~对数据的增删改操作【命令行模式】
1.插入单条数据:insert into tablename(字段名1,字段名2,...) values(值1,值2,...); 从图中可以看出,插入时不需要每个字段都有值(在没有相关的约束前提下), ...
- apache配置,禁止ip访问web站点
由于一台服务器上面部署了好几个应用,对应不同的域名,如果用户知道ip地址的话,直接用户ip地址访问,会显示第一个虚拟主机的页面(更改了虚拟主机的顺序,每次都是显示第一个).这样对用户造成不好的印象,所 ...
- SVN同步出现问题
1.错误描述 同步SVNStatusSubscribe时报告了错误,1中的0个资源已经同步 同步/frame时发生错误:Error getting status for resource ...
- http协议的补充二
一,浏览器到服务器request 1.1,浏览器里面的内容 请求(浏览器->服务器) GET /day09/hello HTTP/1.1 Host: localhost:8080 User-Ag ...
- 图片压缩上传Thumbnailator 插件
一,接口已经写死 public static String upload(String appCode, MultipartFile inputFile) public static String u ...
- 深究ASP.NET Session
Session 本质 & 访问方法 Session 本质 是 HttpSessionState 类 link Session 访问方法 HttpContext.Session Page.Ses ...
- Js - JQ事件委托( 适用于给动态生成的脚本元素添加事件)
最近一段时间打了一个大仗,现在总算消停点,才有时间来做个总结吧算是: 移动端遇到一个项目,是一个列表的侧滑栏,在我这里用jq写的交互事件.自测各方面都挺好的,美滋滋的给了研发.研发也美滋滋的开始开发. ...