Perhaps not the best approach due to the inconsistent vertical positioning of ¹²³ vs. the other numbers… Alternatively, you could use axis post-selection to achieve the same effect.
-
-
Save barionleg/69c3fed77240599a820f95ea4d941987 to your computer and use it in GitHub Desktop.
Superscript Format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| license: gpl-3.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <meta charset="utf-8"> | |
| <style> | |
| .axis path, | |
| .axis line { | |
| fill: none; | |
| stroke: #000; | |
| shape-rendering: crispEdges; | |
| } | |
| .axis text { | |
| font: 13px "helvetica neue"; | |
| } | |
| </style> | |
| <body> | |
| <script src="//d3js.org/d3.v3.min.js"></script> | |
| <script> | |
| var margin = {top: 250, right: 20, bottom: 250, left: 20}, | |
| width = 960 - margin.left - margin.right, | |
| height = 500 - margin.top - margin.bottom; | |
| var superscript = "⁰¹²³⁴⁵⁶⁷⁸⁹", | |
| formatPower = function(d) { return (d + "").split("").map(function(c) { return superscript[c]; }).join(""); }; | |
| var x = d3.scale.log() | |
| .domain([1e0, 1e9]) | |
| .range([0, width]); | |
| var xAxis = d3.svg.axis() | |
| .scale(x) | |
| .orient("bottom") | |
| .ticks(10, function(d) { return 10 + formatPower(Math.round(Math.log(d) / Math.LN10)); }); | |
| var svg = d3.select("body").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("g") | |
| .attr("class", "x axis") | |
| .attr("transform", "translate(0," + height + ")") | |
| .call(xAxis); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment