<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="../bower_components/underscore/underscore-min.js"></script>
<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;
} .bubble {
display: inline-block;
fill: purple;
fill-opacity: 0.5;
stroke: black;
stroke-weight: 1px;
} .axis path, .axis line {
fill: none;
stroke: #000;
stroke-width: 1px;
shape-rendering: crispEdges;
} </style>
</head>
<body>
<section id="chartArea"></section>
<script>
var dataset = _.map(_.range(30), function(num) {
return {
x: Math.round(Math.random() * 100),
y: Math.round(Math.random() * 100),
r: Math.round(5 + Math.random() * 10)
};
}), //reandom generate 15 data from 1 to 50
margin = {top: 20, right: 20, bottom: 40, left: 40},
w = 400 - margin.left - margin.right,
h = 300 - margin.top - margin.bottom; var svg = d3.select('#chartArea').append('svg')
.attr('width', w + margin.left + margin.right)
.attr('height', h + margin.top + margin.bottom)
.append('g') //The last step is to add a G element which is a graphics container in SBG.
.attr('transform', 'translate(' + margin.left + ', ' + margin.top + ')'); //Then offset that graphic element by our left and top margins. var yScale = d3.scale.linear()
.domain([0, d3.max(dataset, function(d) {
return d.y; //tell the max function just need to care about y prop
})])
.range([h, 0]); var yAxis = d3.svg.axis()
.scale(yScale)
.orient('left')
.ticks(10)
.innerTickSize(10)
.outerTickSize(10)
.tickPadding(10);
svg.append('g')
.attr('class', 'y axis')
.attr('transform', 'translate(0,0)')
.call(yAxis); var xScale = d3.scale.linear()
.domain([0, 100])
.range([0, w]); var xAxis = d3.svg.axis()
.scale(xScale)
.orient('bottom')
.ticks(10)
.innerTickSize(6)
.outerTickSize(12)
.tickPadding(12); svg.append('g')
.attr('class', 'x axis')
.attr('transform', 'translate(0, ' + h + ')')
.call(xAxis); svg.selectAll('circle')
.data(dataset)
.enter()
.append('circle')// svg doesn't have div, use rect instead
.attr('class', "bubble")
.attr('cx', function(each_data, index) {
return xScale(each_data.x);
})
.attr('cy', function(each_data) {
return yScale(each_data.y);
})
.attr('r', function(each_data, i) {
return each_data.r;
});
</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>

[D3] 10. Creating Axes with D3的更多相关文章

  1. [D3] Create Chart Axes with D3 v4

    Most charts aren’t complete without axes to provide context and labeling for the graphical elements ...

  2. [D3] 12. Basic Transitions with D3

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  3. [D3] Create DOM Elements with D3 v4

    Change is good, but creating from scratch is even better. This lesson shows you how to create DOM el ...

  4. d3可视化实战00:d3的使用心得和学习资料汇总

    最近以来,我使用d3进行我的可视化工具的开发已经3个月了,同时也兼用其他一些图表类库,自我感觉稍微有点心得.之前我也写过相关文章,我涉及的数据可视化的实现技术和工具,但是那篇文章对于项目开发而言太浅了 ...

  5. [D3 + AngularJS] 15. Create a D3 Chart as an Angular Directive

    Integrating D3 with Angular can be very simple. In this lesson, you will learn basic integration as ...

  6. [D3] Modify DOM Elements with D3 v4

    Once you can get hold of DOM elements you’re ready to start changing them. Whether it’s changing col ...

  7. [D3] Select DOM Elements with D3 v4

    Before you can create dazzling data driven documents, you need to know how D3 accesses the DOM. This ...

  8. [D3] Creating a D3 Force Layout in React

    Learn how to leverage d3's layout module to create a Force Layout inside of React. We'll take a look ...

  9. D3、EChart、HighChart绘图demol

    1.echarts:   <!DOCTYPE html>   <html>   <head>   <meta charset="utf-8" ...

随机推荐

  1. poj 1273

    网络流之最大流的基础题: 可以使用dinic算法和EK算法: 分别对着模板敲了一遍: dinic: #include<cstdio> #include<cstring> #in ...

  2. OneAlert 入门(三)——事件分析

    OneAlert 是国内首个 SaaS 模式的云告警平台,集成国内外主流监控/支撑系统,实现一个平台上集中处理所有 IT 事件,提升 IT 可靠性.有了 OneAlert,你可以更快更合理地为事件划分 ...

  3. Android 系统功能设置菜单 LinearLayout与relativeLayout的实现

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  4. FFMPEG-数据结构解释(AVCodecContext,AVStream,AVFormatContext)

    http://blog.csdn.net/yuan892173701/article/details/8702333 AVCodecContext  这是一个描述编解码器上下文的数据结构,包含了众多编 ...

  5. 关于Team Leader

    他的生日3.16,结婚是在7月- 我感觉他领会整体架构方案的能力很强,几乎每次都能选择一个最优化的方案,比我这具体干活的想到更多更周全.但缺点是,不懂细活还是只能被下人拿捏.因为计算机环境那么复杂,每 ...

  6. Handler sendMessage 与 obtainMessage (sendToTarget)

    这篇文章讲的很好: http://www.cnblogs.com/android007/archive/2012/05/10/2494766.html 两种用法: 1. private void se ...

  7. ListView 的position和id的区别

    我们在使用ListView的时候,一般都会为ListView添加一个响应事件android.widget.AdapterView.OnItemClickListener.本文主要在于对OnItemCl ...

  8. WordPress WooCommerce ‘hide-wc-extensions-message’参数跨站脚本漏洞

    漏洞名称: WordPress WooCommerce ‘hide-wc-extensions-message’参数跨站脚本漏洞 CNNVD编号: CNNVD-201310-501 发布时间: 201 ...

  9. SQL Server 字段状态判断语句

    selct newName=case when  条件 then '否' else '是' end from tableName

  10. Muduo-Base-Exception(未完待续)

    Exception类 主要功能: 能够对异常信息进行输出 能够输出调用的关系 方便我们对某些信息进行调试 系统调用:#include <execinfo.h>int backtrace(v ...