block by enjalot 2f0f6176a0a2473a560d

tickValues

Full Screen

Demo of tickValues

Built with blockbuilder.org

forked from davo‘s block: tickValues

index.html

<!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
  <style>
    body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
    svg { width: 100%; height: 100%; font-family: Helvetica, Arial, _sans; font-size: .75em; }
		
    .axis text {
      font: 10px sans-serif;
    }

    .axis path, .axis line {
      fill: none;
      stroke: #000;
      shape-rendering: crispEdges;
    }
    .caption {
      font-weight: bold;
    }
  </style>
</head>

<body>
  <script>
    
    var vertigo = [1,2,3,14];
    
    var width = 960,
        height = 500;

    
    var x = d3.scale.linear()
        .domain([0, 100])
        .range([1, 600])

    var xAxis = d3.svg.axis()
        .scale(x).tickSize(13)
        .tickValues([0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100])
    		.tickFormat(function(n) { return n + "%"})
        .orient("bottom");

    var svg = d3.select("body").append("svg")
        .attr("width", width)
        .attr("height", height)
      .append("g")
    		.attr("transform", "translate(" + (width-600) / 2 + "," + height / 2 + ")");
    svg.append("g")
        .attr("class", "x axis")
        .call(xAxis);

    svg.call(xAxis).append("text")
        .attr("class", "caption")
        .attr("y", -9)
        .text("tickValues");
    
  </script>
</body>