zoukankan      html  css  js  c++  java
  • D3.js 用层画条形图

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>testD3-3-drawingDivBar</title>
    <script type="text/javascript" src="http://localhost:8080/spring/js/d3.js"></script>
    <style type="text/css">
    div.bar {
        display: inline-block;
         20px;
        margin-right: 2px;
        background-color: teal;
    }
    </style>
    </head>
    <body>
    <script type="text/javascript">
    
        var dataset = [ 5, 10, 15, 20, 25 ];
    
        d3.select("body").selectAll("div")
            .data(dataset)
            .enter()
            .append("div")
            .attr("class", "bar")
            .style("height", function(d) {
                return (d * 5) + "px";
            });
    
    </script>
    </body>
    </html>

    用层画条形图

    代码解释:

    1.1 为同类层添加样式

    div.bar {
        display: inline-block;
         20px;
        background-color: teal;
    }

    1.2 声明要为某类层设置属性

    .attr("class", "bar")
    

    1.3 为每个特定的层设置属性

    .style("height", function(d) {
        return (d * 5) + "px";
    });
    

    1.4 设置层之间的间隔

    margin-right: 2px;
     
  • 相关阅读:
    Unity NPOI 无法读取xlsx
    spring源码之—Assert.notNull
    手工Ghost安装系统
    一键GHOST优盘版安装XP/win7系统
    oncontextmenu事件
    Maven 常用配置
    U盘装win7系统
    eval json ajax
    Maven--pom.xml 配置详解
    Maven 构建
  • 原文地址:https://www.cnblogs.com/LO-ME/p/5443020.html
Copyright © 2011-2022 走看看