This example uses d3.timeFormatDefaultLocale to change the locale of d3-axis. A more flexible approach is to use d3.timeFormatLocale.
Last active
December 5, 2016 18:28
-
-
Save mbostock/6f1cc065d4d172bcaf322e399aa8d62f to your computer and use it in GitHub Desktop.
Localized Time Axis
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> | |
<svg width="960" height="500"></svg> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script> | |
var svg = d3.select("svg"), | |
margin = {top: 250, right: 40, bottom: 250, left: 40}, | |
width = svg.attr("width") - margin.left - margin.right, | |
height = svg.attr("height") - margin.top - margin.bottom; | |
d3.json("https://unpkg.com/d3-time-format@2/locale/ru-RU.json", function(error, locale) { | |
if (error) throw error; | |
d3.timeFormatDefaultLocale(locale); | |
var x = d3.scaleTime() | |
.domain([new Date(2000, 0, 1), new Date(2001, 0, 1)]) | |
.range([0, width]); | |
svg.append("g") | |
.attr("transform", "translate(" + margin.left + "," + margin.top + ")") | |
.call(d3.axisBottom(x)); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment