标签:shu func value 需要 zha 4.0 attr zhang 分享
序数比例尺的定义域和值域都是离散的。如果需要通过输入一些离散的值得到另一些离散的值,这时候就要考虑序数比例尺。
var ordinal = d3.scale.ordinal() .domain([1,2,3,4,5]) .rangePoints([0,100]); console.log( ordinal.range() ); //输出[0,25,50,75,100] console.log( ordinal(1) ); //输出0 console.log( ordinal(3) ); //输出50 console.log( ordinal(5) ); //输出100 //计算见下图 ordinal.rangePoints([0,100],5); console.log( ordinal.range() ); //输出[27.77,38.88,50,61.11,72.22] ordinal.rangeRoundPoints([0,100],5); console.log( ordinal.range() ); //输出[28,39,50,61,72] var bands = d3.scale.ordinal() .domain([1,2,3,4,5]) .rangeBands([0,100]); //计算见下图 console.log( bands.range() ); //输出[0,20,40,60,80] console.log( bands.rangeBand() ); //输出20 bands.rangeBands([0,100],0.5,0.2); console.log( bands.range() ); //输出[4.081632653061225,24.489795918367346,44.89795918367347,65.3061224489796,85.71428571428571] console.log( bands.rangeBand() ); //输出10.204081632653061
step的计算
var color = d3.scale.category10(); console.log( color(1) ); //输出颜色中的第一个 console.log( color("zhangsan") ); //输出颜色中的第一个 .attr("fill".function(d,i){ return color(i); //color是颜色比例尺,i是被绑定数据的索引hao })
标签:shu func value 需要 zha 4.0 attr zhang 分享
原文地址:http://www.cnblogs.com/lmjZone/p/7739251.html