html D3byEX 5.5:线性比例(适用于D3.js v4)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html D3byEX 5.5:线性比例(适用于D3.js v4)相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html>
<meta charset=utf-8>
<head>
<meta name="description" content="D3.js v4, .scaleLinear" />
</head>
<body>
<script src="http://d3js.org/d3.v4.min.js"></script>
<script>
var url = "https://gist.githubusercontent.com/d3byex/e5ce6526ba2208014379/raw/8fefb14cc18f0440dc00248f23cbf6aec80dcc13/walking_dead_s5.csv";
d3.csv(url, function (error, data) {
var mappedAndConverted = data.map(function (d) {
return {
Episode: +d.Episode, // unary oper converts str to int
USViewers: +d.USViewers,
Title: d.Title
};
});
var viewership = mappedAndConverted.map(function (d) { return d.USViewers; });
var minViewership = d3.min(viewership);
var maxViewership = d3.max(viewership);
var minBarHeight = 100, maxBarHeight = 400;
var yScale = d3.scaleLinear() // v4
.domain([minViewership, maxViewership])
.range([minBarHeight, maxBarHeight]);
// view console
console.log(minViewership + " -> " + yScale(minViewership)); // 100
console.log(maxViewership + " -> " + yScale(maxViewership)); // 400
});
</script>
</body>
</html>
以上是关于html D3byEX 5.5:线性比例(适用于D3.js v4)的主要内容,如果未能解决你的问题,请参考以下文章
html D3byEX 4.6:顶轴(适用于D3.js v4)
html D3byEX 4.4:底轴(适用于D3.js v4)
html D3byEX 9.10:符号(适用于D3.js v4)
html D3byEX 7.4:链式转换(适用于D3.js v4)
html D3byEX 6.1:散点图(适用于D3.js v4)
html D3byEX 7.2:动画多个属性(适用于D3.js v4)