Skip to content

Instantly share code, notes, and snippets.

@lhstock
Last active February 27, 2017 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lhstock/42dd070c79eeeac494d31712bf99f43f to your computer and use it in GitHub Desktop.
Save lhstock/42dd070c79eeeac494d31712bf99f43f to your computer and use it in GitHub Desktop.
d3.scaleOrdinal()
license: mit
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://d3js.org/d3.v4.min.js"></script>
</head>
<body>
</body>
<script>
var width = 500,height = 500,padding = {left:20,right:20};
var data = ["tang","song","yuan","ming","qing"];
var axis_length = width - padding.left - padding.right;
//d3.scaleImplicit = 200;
var svg = d3.select("body").append("svg")
.attr("width",width)
.attr("height",height)
var scale = d3.scaleOrdinal()
.domain(data)
.range([0,100,200,300,400])
// .unknown(500);
console.log(scale("ceshi"));
var axis = d3.axisBottom()
.scale(scale)
.ticks(5)
svg.append("g").call(axis).attr("transform","translate("+ (padding.left) +","+(height - 100)+")");
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment