简体   繁体   English

D3JS中的自定义轴功能

[英]Custom axis function in D3JS

I'm using D3JS and I want an axis in x with this kind of values : 125, 250, 500, 1000 ... until 8000. So multiply by 2 my values each time. 我正在使用D3JS,我希望x中的轴具有这样的值:125,250,500,1000 ......直到8000.所以每次乘以2我的值。

So I tried a Quantize Scales but axis do not support it. 所以我尝试了Quantize Scales但轴不支持它。

How can I do this ? 我怎样才能做到这一点 ? Can I do a custom mathematical function like y = mx + b (where m = 2 in my case and b = 0) and use it in axis? 我可以做一个自定义的数学函数,比如y = mx + b(在我的情况下m = 2,b = 0)并在轴上使用它吗?

Here you can see my code 在这里你可以看到我的代码

Podelo

The linear scale is pretty flexible if you mass in multiple values for the range and domain to create a polylinear scale: 如果您为范围和域创建多个值以创建多线性比例,线性比例非常灵活:

tickWidth = (ChartWidth - padding)/7
xScale = d3.scale.linear()
           .domain([0, 125, 250, 500, 1000, 2000, 4000, 8000])
           .range(d3.range(8).map(function(d){ return d*tickWidth; }));

http://jsfiddle.net/h2juD/6/ http://jsfiddle.net/h2juD/6/

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

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