【D3.js数据可视化系列教程】(二十六)--加载SVG文件

1. Rect01.svg文件

用到d3.xml函数,第一个参数是地址,第二个参数是个回调函数

<?xml version="1.0" standalone="no"?>   
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"   
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">  
<svg width="12cm" height="4cm" viewBox="200 200 1200 400"  
     xmlns="http://www.w3.org/2000/svg" version="1.1">  
    
  <desc>Example rect01 - rectangle with sharp corners</desc>   
    
  <rect x="100" y="1" width="1198" height="398"  
        fill="none" stroke="blue" stroke-width="2"/>   
   
  <rect x="100" y="200" width="400" height="200"  
        fill="yellow" stroke="navy" stroke-width="10"  />   
</svg> 

  2. 加载SVG

d3.xml("http://localhost:8080/spring/D3data/Rect01.svg", "image/svg+xml", //加载文件  
function(xml) {  
   document.body.appendChild(xml.documentElement);//添加DOM节点  
});

  3. 效果

  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值