Book Image

Data Visualization with D3 and AngularJS

By : Erik Hanchett, Christoph Körner
Book Image

Data Visualization with D3 and AngularJS

By: Erik Hanchett, Christoph Körner

Overview of this book

Table of Contents (16 chapters)
Data Visualization with D3 and AngularJS
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

All about axes


Until now, we just scaled our dataset without drawing a single shape on the screen. For the next step, I want to introduce d3.svg.axis(), a built-in function to draw axes and labels. This function makes it very easy and comfortable to add an axis to a chart, as shown in the following code:

var axis = d3.svg.axis();

First, we create a new axis object with d3.svg.axis(), which we can then configure by calling different methods on it. I will now discuss the most important of these methods:

  • axis.scale([scale]): This adds scaling to an axis as follows:

    var scale = d3.scale.linear()
      .domain([0, 10])
      .range([0, 100]);
    
    var axis = d3.svg.axis()
      .scale(scale);
  • axis.orient([orientation]): This specifies an orientation of the ticks values relative to the axis. The orientation can be top, bottom, left, or right:

    var axis = d3.svg.axis()
      .orient('bottom');
  • axis.ticks([arguments…]): This specifies the tick number or interval relative to the given scale, as shown in the following code...