简体   繁体   English

D3下降刻度

[英]D3 descending scale

Given a set of number 0 to 1, I need a d3 scaling function that returns 0 to 100. 给定一组数字0到1,我需要一个d3缩放函数,该函数返回0到100。

var scale = d3.scale.linear();
scale.domain([0,1]);
scale.range([0,100]);
scale(0.1);  // 10

This works great. 这很好。 However, because I'm setting opacity for data elements based on confidence intervals, I want the output (range) to diminish as the input (domain) increases. 但是,由于我要根据置信区间为数据元素设置不透明度,因此我希望输出(范围)随着输入(域)的增加而减小。

So for example: 因此,例如:

scale(0.1);  // should produce 90
scale(0.2);  // should produce 80
scale(0.3);  // should produce 70

So as the scale input goes up, the output goes down. 因此,当比例输入增加时,输出减少。

How can I instruct the scale object to do this? 如何指示比例对象执行此操作?

You simply need to provide a range that behaves accordingly: 您只需要提供一个行为相应的范围:

scale.range([100,0]);

Note that you could also reverse the domain in this case with the same effect. 请注意,在这种情况下,您也可以反转域,效果相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM