【D3.js数据可视化系列教程】--(八)使用D3绘制SVG
来源:互联网 发布:软件测评师考试内容 编辑:程序博客网 时间:2024/04/30 02:09
1 创建SVG
// SVG尺寸var w = 500;var h = 50;var svg = d3.select("body") .append("svg") .attr("width", w) // 设置高宽 .attr("height", h);
2 数据驱动的SVG
var dataset = [ 5, 10, 15, 20, 25 ];var circles = svg.selectAll("circle") .data(dataset) .enter() .append("circle");circles.attr("cx", function(d, i) { return (i * 50) + 25; }) .attr("cy", h/2) .attr("r", function(d) { return d; });
3 源码
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>testD3-7-drawSVG.html</title> <script type="text/javascript" src="http://localhost:8080/spring/js/d3.js"></script><style type="text/css"> </style></head><body><script type="text/javascript"> // SVG尺寸 var w = 500; var h = 50; // 数据 var dataset = [ 5, 10, 15, 20, 25 ]; // 创建SVG容器 var svg = d3.select("body") .append("svg") .attr("width", 500) .attr("height", 50); // 创建圆 var circles = svg.selectAll("circle") .data(dataset) .enter() .append("circle"); // 根据数据设置每个圆的属性 circles.attr("cx", function(d, i) { return (i * 50) + 25; }) .attr("cy", h/2) .attr("r", function(d) { return d; });</script></body></html>
4 效果
- 【D3.js数据可视化系列教程】--(八)使用D3绘制SVG
- 【D3.V3.js数据可视化系列教程】--(八)绘制SVG
- 【D3.js数据可视化系列教程】--(七)SVG初探
- 【D3.js数据可视化系列教程】--(十五)SVG基本图形绘制
- 【D3.js数据可视化系列教程】--(四)使用数据
- 【D3.js数据可视化系列教程】(二十六)--加载SVG文件
- 【D3.V3.js数据可视化系列教程】--(七)SVG概要
- 【D3.js数据可视化系列教程】--(三)数据绑定
- 【D3.js数据可视化系列教程】--(一)简介
- 【D3.js数据可视化系列教程】--(六)生成测试数据
- 【D3.js数据可视化系列教程】--(十一)散点图
- 【D3.js数据可视化系列教程】--(十二)比例尺
- 【D3.js数据可视化系列教程】--(十三)坐标轴
- 【D3.js数据可视化系列教程】(二十八)--弦图
- 【D3.js数据可视化系列教程】(三十四)-- sankey图
- 【D3.js数据可视化系列教程】(三十五)-- 矩形树
- 【D3.js数据可视化系列教程】(三十六)-- 冰柱图
- 【D3.V3.js数据可视化系列教程】--(一)简介
- 九江学院史上最牛的毕业选题要求......看完之后寝室爆笑.....
- Maven工程的搭建
- POJ 1663Number Steps
- 一、数据库系统的基本概念
- 使用Custom Draw优雅的实现ListCtrl的重绘
- 【D3.js数据可视化系列教程】--(八)使用D3绘制SVG
- POJ 1067
- 1029. Median (25) @ PAT (Advanced Level) Practise
- Write-through和Write-back
- android系统mount详情--vold.fstab (转载)
- [C语言]菜鸟的一些理解-字符串
- Android当中切换图片
- 今日学习linux心得体会
- hdu 1217 Arbitrage