【D3.V3.js数据可视化系列教程】--(七)SVG概要

【D3.V3.js系列教程】--(七)SVG概要

一、简单形状

 

有一些视觉元素可以包含那些SVG标签,包括矩形圆形椭圆形线条文字路径之间

基于像素的坐标系统,其中0,0是左上角的绘图空间。增加x值向右移动,同时增加Ÿ值向下移动。

正确绘制一个矩形。使用xy的指定左上角的坐标,宽度高度指定的尺寸。我们SVG的矩形填充整个空间:

<rect x="0" y="0" width="500" height="50"/>

画出一个圆。使用cxcy,指定指定半径中心的坐标,和ŗ因为它CX(“X轴”)的值是250,这个圈子围绕在中间的500像素宽的SVG 

<circle cx="250" cy="25" r="25"/>

椭圆形相似,但每个轴的预期不同的半径值。相反ŗ,使用RXRY

<ellipse cx="250" cy="25" rx="100" ry="25"/>

线画一条线。使用x1Y1到指定线的一端的坐标,和的2倍y2指定的另一端的坐标。中风颜色必须指定为线,是可见的。

<line x1="0" y1="0" x2="500" y2="50" stroke="b​​lack"/>

文本呈现文本。使用 X  指定的左边缘的位置,Ÿ指定类型的基线的垂直位置

<text x="250" y="25">易peasy </文>

文本将继承其父元素的CSS指定的字体样式,除非另有规定。(在某一时刻的造型文本。)注意上面的示例文本的格式,本段比赛。我们可以覆盖,格式如下:

<文本=“250”Y =“25”字体家庭=“无衬线”
 字体大小=“25”填充“灰色”>易peasy </文字的>

、SVG的默认样式

SVG的默认样式没有中风是黑色填充。如果你想别的,你就必须将样式应用到你的元素。常见的SVG性质:

  • 填充 -颜色值。正如用CSS,颜色可以被指定为

    • 命名的颜色- 橙色
    • 十六进制值- #3388aa38A
    • RGB值- RGB(10,150,20)
    • RGB与Alpha透明度- RGBA(10,150,20,0.5)
  • 行程 -颜色值。
  • 中风宽度 -数字测量(通常以像素为单位)。
  • 不透明度 -  0.0(完全透明)和1.0(完全不透明)之间的数值。

有了文字,也可以使用这些特性,这就像在CSS工作:

  • 字体家庭
  • 字体大小

三、源码

  1. <!DOCTYPE html>  
  2. <html>  
  3.   <head>  
  4.         <meta charset="utf-8">  
  5.         <title>testD3-6-SVG.html</title>  
  6.         <script type="text/javascript" src="http://localhost:8080/spring/js/d3.v3.js"></script>  
  7.     <style type="text/css">  
  8.     .pumpkin {  
  9.     fill: yellow;  
  10.     stroke: orange;  
  11.     stroke-width: 5;  
  12.  }  
  13.         </style>  
  14.     </head>  
  15.     <body>  
  16.         <script type="text/javascript">  
  17.         </script>  
  18. <svg>  
  19.   
  20. <rect x="0" y="0" width="500" height="50"/>  
  21. <ellipse cx="250" cy="225" rx="100" ry="25"/>  
  22. <line x1="0" y1="120" x2="500" y2="50" stroke="black"/>  
  23. <text x="250" y="155" font-family="sans-serif"  
  24.  font-size="25" fill="gray">Easy-peasy</text>  
  25. <circle cx="25" cy="80" r="20"  
  26.         fill="rgba(128, 0, 128, 0.75)"   
  27.         stroke="rgba(0, 255, 0, 0.25)"   
  28.         stroke-width="100"/>  
  29. <circle cx="75" cy="80" r="20"  
  30.         fill="rgba(0, 255, 0, 0.75)"  
  31.         stroke="rgba(0, 0, 255, 0.25)" stroke-width="10"/>  
  32. <circle cx="125" cy="80" r="20"  
  33.         fill="rgba(255, 255, 0, 0.75)"  
  34.         stroke="rgba(255, 0, 0, 0.25)" stroke-width="10"/>  
  35. <rect x="0" y="300" width="30" height="30" fill="purple"/>  
  36. <rect x="20" y="305" width="30" height="30" fill="blue"/>  
  37. <rect x="40" y="310" width="30" height="30" fill="green"/>  
  38. <rect x="60" y="315" width="30" height="30" fill="yellow"/>  
  39. <rect x="80" y="320" width="30" height="30" fill="red"/>  
  40. <circle cx="25" cy="425" r="22" class="pumpkin"/>  
  41. <circle cx="25" cy="525" r="20" fill="rgba(128, 0, 128, 1.0)"/>  
  42. <circle cx="50" cy="525" r="20" fill="rgba(0, 0, 255, 0.75)"/>  
  43. <circle cx="75" cy="525" r="20" fill="rgba(0, 255, 0, 0.5)"/>  
  44. <circle cx="100" cy="525" r="20" fill="rgba(255, 255, 0, 0.25)"/>  
  45. <circle cx="125" cy="525" r="20" fill="rgba(255, 0, 0, 0.1)"/>  
  46. <circle cx="25" cy="625" r="20" fill="purple"   
  47.         stroke="green" stroke-width="10"  
  48.         opacity="0.9"/>  
  49. <circle cx="65" cy="625" r="20" fill="green"  
  50.         stroke="blue" stroke-width="10"  
  51.         opacity="0.5"/>  
  52. <circle cx="105" cy="625" r="20" fill="yellow"  
  53.         stroke="red" stroke-width="10"  
  54.         opacity="0.1"/>  
  55. </svg>  
  56.     </body>  
  57. </html>  
<!DOCTYPE html>
<html>
  <head>
		<meta charset="utf-8">
		<title>testD3-6-SVG.html</title>
		<script type="text/javascript" src="http://localhost:8080/spring/js/d3.v3.js"></script>
	<style type="text/css">
	.pumpkin {
    fill: yellow;
    stroke: orange;
    stroke-width: 5;
 }
		</style>
	</head>
	<body>
		<script type="text/javascript">
		</script>
<svg>

<rect x="0" y="0" width="500" height="50"/>
<ellipse cx="250" cy="225" rx="100" ry="25"/>
<line x1="0" y1="120" x2="500" y2="50" stroke="black"/>
<text x="250" y="155" font-family="sans-serif"
 font-size="25" fill="gray">Easy-peasy</text>
<circle cx="25" cy="80" r="20"
        fill="rgba(128, 0, 128, 0.75)" 
        stroke="rgba(0, 255, 0, 0.25)" 
        stroke-width="100"/>
<circle cx="75" cy="80" r="20"
        fill="rgba(0, 255, 0, 0.75)"
        stroke="rgba(0, 0, 255, 0.25)" stroke-width="10"/>
<circle cx="125" cy="80" r="20"
        fill="rgba(255, 255, 0, 0.75)"
        stroke="rgba(255, 0, 0, 0.25)" stroke-width="10"/>
<rect x="0" y="300" width="30" height="30" fill="purple"/>
<rect x="20" y="305" width="30" height="30" fill="blue"/>
<rect x="40" y="310" width="30" height="30" fill="green"/>
<rect x="60" y="315" width="30" height="30" fill="yellow"/>
<rect x="80" y="320" width="30" height="30" fill="red"/>
<circle cx="25" cy="425" r="22" class="pumpkin"/>
<circle cx="25" cy="525" r="20" fill="rgba(128, 0, 128, 1.0)"/>
<circle cx="50" cy="525" r="20" fill="rgba(0, 0, 255, 0.75)"/>
<circle cx="75" cy="525" r="20" fill="rgba(0, 255, 0, 0.5)"/>
<circle cx="100" cy="525" r="20" fill="rgba(255, 255, 0, 0.25)"/>
<circle cx="125" cy="525" r="20" fill="rgba(255, 0, 0, 0.1)"/>
<circle cx="25" cy="625" r="20" fill="purple" 
        stroke="green" stroke-width="10"
        opacity="0.9"/>
<circle cx="65" cy="625" r="20" fill="green"
        stroke="blue" stroke-width="10"
        opacity="0.5"/>
<circle cx="105" cy="625" r="20" fill="yellow"
        stroke="red" stroke-width="10"
        opacity="0.1"/>
</svg>
	</body>
</html>


 

四、效果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值