API 案例 d3.scaleOrdinal() https://bl.ocks.org/lhstock/42dd070c79eeeac494d31712bf99f43f
Last active
February 27, 2017 05:58
-
-
Save lhstock/42dd070c79eeeac494d31712bf99f43f to your computer and use it in GitHub Desktop.
d3.scaleOrdinal()
This file contains 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: mit |
This file contains 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> | |
<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