Skip to content

Instantly share code, notes, and snippets.

@githubjeka
Created October 28, 2016 11:32

Revisions

  1. githubjeka created this gist Oct 28, 2016.
    1 change: 1 addition & 0 deletions .block
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    license: gpl-3.0
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    Some examples for [d3-axis](https://github.com/d3/d3-axis/)
    64 changes: 64 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    <!DOCTYPE html>
    <head>
    <script src="https://d3js.org/d3.v4.min.js"></script>
    <meta charset="utf-8">
    <style>
    svg > g:first-child {
    transform: translateX(300px)
    }

    svg > g:nth-child(2) {
    transform: translate(10px, 20px)
    }

    svg > g:nth-child(3) {
    transform: translate(10px, 50px)
    }

    svg > g:nth-child(4) {
    transform: translate(300px, 50px)
    }

    svg > g:last-child {
    transform: translate(10px, 300px)
    }
    </style>
    </head>
    <body>
    <script>
    var linearScale = d3.scaleLinear()
    .domain([0, 100])
    .range([0, 200])
    ;

    var svg = d3.select("body")
    .attr('class', 'axis')
    .append("svg")
    .attr('width', 960)
    .attr('height', 500);

    var newGroupForAxis = function (axis) {
    svg.append("g").call(axis)
    };

    newGroupForAxis(d3.axisBottom(linearScale));
    newGroupForAxis(d3.axisTop(linearScale));
    newGroupForAxis(d3.axisRight(linearScale));
    newGroupForAxis(d3.axisLeft(linearScale));

    var timeScale = d3.scaleTime()
    .domain([new Date(), (new Date()).setDate((new Date).getDate() + 3)])
    .range([0, 500])
    ;

    newGroupForAxis(
    d3.axisBottom(timeScale)
    .ticks(d3.timeHour.every(12))
    .tickSizeInner(15)
    .tickSizeOuter(5)
    .tickPadding([6])
    );

    </script>

    </body>