如何避免在图中使用d3.js的日志零 [英] How to avoid log zero in graph using d3.js
问题描述
我目前正在使用库d3.js.我有线图使用
动态线图< a>
这里我们有绘制功率线性和对数的选项。
但是我的问题是,我可能在我的数据集中有一些值为零,因为日志0是未定义的,所以代码无法绘制它。
这里在我的代码中的比例设置像这样
I am current working on library d3.js.I have line graph using Dynamic Line Graph Here we have option of drawing power linear and log. But my problem is that I might have some values zero in my data set and as log 0 is undefined so the code is unable to plot it. Here in my code the scale set like this
y = d3.scale.log().domain([0.1, max_y _value]).range([h, 0]).nice();
这是如何使用的
lineFunction = d3.svg.line()
.y(function(d) {
return y(d);
});
我知道它的一个奇怪的问题。但是有一种方法,我可以处理log 0值所以如果我有单个零值,其余的正确绘制。
我可以在同一语句中给出两个域和范围(以处理0值)如果是,它将如何绑定到y轴?
I know that its an odd question.But is there a way by which I can handle log 0 value so that if I have single zero value the rest of them are plotted correctly. Can I gave two domain and range in same statement (to handle 0 value) if yes than how will it bind to y axis?
感谢任何帮助。
推荐答案
问题,方法是使用钳位功能。这是我改变代码的方式:
I solved my problem by using a clamp function. This is how I have changed the code:
y = d3.scale.log().clamp(true).domain([0.1, max_y _value]).range([h, 0]).nice();
这篇关于如何避免在图中使用d3.js的日志零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!