简体   繁体   English

d3.js:获取输入域范围之外的刻度值

[英]d3.js: get tick values outside extent of input domain

Given a list of values 给定值列表

var values = [245, 483, 498, 597, 726, 788, 799, 974];

I want to get tick values that "surround" the extent of the values domain: 我想刻度值即“环绕”的程度values域:

// [200, 300, 400, 500, 600, 700, 800, 900, 1000]

Using the following does not work for this intent: 为此,使用以下命令无效:

var scale = d3.scale.linear().domain(d3.extent(values));
var ticks = scale.ticks(9);
// [300, 400, 500, 600, 700, 800, 900] == ticks

That is no surprise since the D3.js reference says: 这并不奇怪,因为D3.js参考说明:

The returned tick values are […] guaranteed to be within the extent of the input domain. 返回的滴答值保证[…]在输入域的范围内。

Use .nice() : 使用.nice()

var values = [245, 483, 498, 597, 726, 788, 799, 974];
var scale = d3.scale.linear().domain(d3.extent(values)).nice();
var ticks = scale.ticks(9);

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

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