Most charts aren’t complete without axes to provide context and labeling for the graphical elements being displayed. This lesson introduces D3’s APIs for creating, customizing, and displaying axes while building on topics from previous lessons.

var margin = { top: 10, right: 20, bottom: 60, left: 25 };
var width = 425 - margin.left - margin.right;
var height = 625 - margin.top - margin.bottom; var svg = d3.select('.chart')
.append('svg')
.attr('width', width + margin.left + margin.right)
.attr('height', height + margin.top + margin.bottom)
.append('g')
.attr('transform', `translate(${margin.left}, ${margin.top})`); svg.append('rect')
.attr('width', width)
.attr('height', height)
.style('fill', 'lightblue')
.style('stroke', 'green'); /**
* Create Y axis
*/
// Set scale
const yScale = d3.scaleLinear()
.domain([0, 100])
.range([height, 0]);
// add y-axis
const yAxis = d3.axisLeft(yScale);
// const yAxis = d3.axisLeft(yScale).ticks(10, '.1s');
// If you want to add fine control about the ticks:
// const yAxis = d3.axisLeft(yScale).tickValues([5,10,30,50,80,100]);
// add to the svg
svg.call(yAxis); /**
* Create X axis
*/
const xScale = d3.scaleTime()
.domain([new Date(2017, 6, 1), new Date(2017, 7, 1)])
.range([0, width]); //https://github.com/d3/d3-time
const xAxis = d3.axisBottom(xScale)
.ticks(d3.timeDay.every(4))
.tickSize(10)
.tickPadding(15); svg.append('g')
.attr('transform', `translate(0, ${height})`)
.call(xAxis);

最新文章

  1. c++用法的学习心得
  2. ArrayList数组列表
  3. wex5 实战 框架拓展之1 公共data组件(Data)
  4. 运行Maven是报错:No goals have been specified for this build
  5. Excel 数值转换为人民币大写金额字符串
  6. Java学习-011-创建文件实例及源代码
  7. webqq协议请求交互过程
  8. MySQL · 特性分析 · 内部临时表
  9. 读书笔记-UIView与控件
  10. Linux之文件压缩与解压
  11. SpringMVC源码情操陶冶-AbstractHandlerMethodMapping
  12. 【前端酷站】分享一个纯 Javascript 的图表库与立体像素风制作~
  13. 使用100%面向过程的思维方式来写java程序
  14. 纯MATLAB版本 SIFT代码
  15. 【NLP】新词发现
  16. hdu 3905(dp)
  17. Java设计模式(13)——结构型模式之桥梁模式(Bridge)
  18. ResultSet 可滚动性和可更新性
  19. Treflection04_面试题
  20. node.js+express+jade系列五:ajax登录

热门文章

  1. 【安卓】数据库基于脚本的"增量更新",每次更新时不需改动java代码、!
  2. [Python] Read and Parse Files in Python
  3. JS中的onload与jQuery中的ready差别
  4. c++中六种构造函数的实现以及9中情况下,构造函数的调用过程
  5. [Java开发之路](9)对象序列化与反序列化
  6. 想学android进来看看吧~ ~
  7. CSS盒子模型图
  8. HTML5入门:HTML5的文档声明和基本代码
  9. IIS文件上传大小修改配置说明
  10. 项目融入mongoDB