1. svg should use 'fill' prop instead 'background-color'
2. svg width & height no need 'px'
3. attr(function(data_val, index){})
4. create svg, d3.select('selector').append('svg').attr('width', xxx).attr('height', xx)
5. svg should use 'rect' instead of 'div'
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="../ventor/d3.min.js"></script>
<style type="text/css"> body
{
padding-top: 50px;
padding-left: 100px; } #chartArea {
width: 400px;
height: 300px;
background-color: #CCC;
} .bar
{
display: inline-block;
width: 20px;
height: 75px; /* Gets overriden by D3-assigned height below */
margin-right: 2px;
fill: teal; /* SVG doesn't have background prop, use fill instead*/
z-index:99;
} </style>
</head>
<body>
<section id="chartArea"></section>
<script>
var dataset = [3,5,7,9,4,6];
var svg = d3.select('#chartArea').append('svg')
.attr('width', 400)
.attr('height', 300); //svg deosn't need 'px' svg.selectAll('div')
.data(dataset)
.enter()
.append('rect')// svg doesn't have div, use rect instead
.attr('class', "bar")
.attr('width', 20)
.attr('x', function(each_data, index){
return index * 22;
})
.attr('y', function(each_data){
return 300-each_data*10;
})
.attr('height', function(each_data, i){
return each_data * 10; // svg doesn't have 'style'
});
</script> <!--
1. svg should use 'fill' prop instead 'background-color'
2. svg width & height no need 'px'
3. attr(function(data_val, index){})
4. create svg, d3.select('selector').append('svg').attr('width', xxx).attr('height', xx)
5. svg should use 'rect' instead of 'div'
-->
</body>
</html>

最新文章

  1. Elasticsearch判断多列存在、bool条件组合查询示例
  2. js移动焦点到最后
  3. ProgressDialog弹出时的底色变暗(转)
  4. 对PostgreSQL xmax的理解
  5. TextView实现跑马灯效果
  6. Python串口操作纸币器1
  7. CopyOnWriteArrayList理解与理解
  8. HTTP请求大全
  9. 基本矩张量与strike.dip.rake的对应
  10. Java学习笔记33(IO:打印流,IO流工具类)
  11. xfce的主题
  12. Pig latin基础
  13. ScheduledThreadPoolExecutor 使用线程池执行定时任务
  14. My new English
  15. Beta发布-----欢迎来怼团队
  16. .NET:动态代理的 “5 + 1” 模式
  17. vue 路由传参 、接收参数
  18. 推广Facebook技巧
  19. 抓jsoup_02_数据
  20. unity的技术博客

热门文章

  1. 双积分式(A/D)转换器电路结构及工作原理
  2. ubuntu maven 安装 设置
  3. [原博客] POJ 2484 A Funny Game
  4. Android 连接tomcat模拟登陆账号
  5. 花20分钟写的-大白话讲解如何给github上项目贡献代码
  6. Linux平台下Java调用C函数
  7. bzoj3669
  8. BZOJ_4196_[NOI2015]_软件包管理器_(树链剖分)
  9. 【log4js】
  10. 向SharePoint页面添加后台代码