如果你想有两个靠近边界的边界蜱和蜱(最大最小)值,你可以修改源。
在nv.models.axis(),有当showMaxMin是真正的底/顶部取向给出一个缓冲:
if (showMaxMin && (axis.orient() === 'top' || axis.orient() === 'bottom')) {
var maxMinRange = [];
wrap.selectAll('g.nv-axisMaxMin')
.each(function(d,i) {
try {
if (i) // i== 1, max position
maxMinRange.push(scale(d) - this.getBoundingClientRect().width - 4); //assuming the max and min labels are as wide as the next tick (with an extra 4 pixels just in case)
else // i==0, min position
maxMinRange.push(scale(d) + this.getBoundingClientRect().width + 4)
}catch (err) {
if (i) // i== 1, max position
maxMinRange.push(scale(d) - 4); //assuming the max and min labels are as wide as the next tick (with an extra 4 pixels just in case)
else // i==0, min position
maxMinRange.push(scale(d) + 4);
}
});
// the g's wrapping each tick
g.selectAll('g').each(function(d, i) {
if (scale(d) < maxMinRange[0] || scale(d) > maxMinRange[1]) {
if (d > 1e-10 || d < -1e-10) // accounts for minor floating point errors... though could be problematic if the scale is EXTREMELY SMALL
d3.select(this).remove();
else
d3.select(this).select('text').remove(); // Don't remove the ZERO line!!
}
});
}
我只是删除这些缓冲区:
try {
if (i) // i== 1, max position
maxMinRange.push(scale(d));
else // i==0, min position
maxMinRange.push(scale(d))
}catch (err) {
if (i) // i== 1, max position
maxMinRange.push(scale(d));
else // i==0, min position
maxMinRange.push(scale(d));
}
使用'.tickValues()'而不是'.ticks()'。 – 2014-10-29 09:53:42
我已经尝试过使用'.tickFormat()',但它给了我上面缺少tickLabels的过滤器。另外,使用这个技巧时,隐藏的标签甚至不会显示在工具提示中。我相信'tickValues()'会有相同的结果。 – yonasstephen 2014-10-29 13:24:32
嗯,我会使用x轴的时间尺度 - 这应该可以让您更好地控制所显示的内容。 [这个问题](http://stackoverflow.com/questions/14058876/how-do-i-display-dates-on-the-x-axis-for-nvd3-d3-js)应该是有帮助的。 – 2014-10-29 13:41:15