I'm migrating the parallel coordinates source code here to the newest d3js version (d3js 4.5.0). I'm stuck to this line:
我正在将并行坐标源代码迁移到最新的d3js版本(d3js 4.5.0)。我只能说:
var x = d3.scale.ordinal().rangePoints([0, width], 1)
It seems that in d3js v4 the rangePoints
function does not exist anymore. I can change to d3.scaleOrdinal(), but it has only the range
function, not the rangePoints
function. Any clue on for this?
在d3js v4中,距离点函数似乎不再存在。我可以改成d3.scaleOrdinal(),但是它只有range函数,而不是rangePoints函数。有什么线索吗?
1 个解决方案
#1
12
In D3 v4, two new scales were created: scaleBand
and scalePoint
, which now have some of the features that scale.ordinal
had in version 3 (among them rangePoints
).
在D3 v4中,创建了两个新的scale: scaleBand和scalePoint,它们现在具有一些可伸缩的特性。序号在第三版中(其中有距离点)。
It's documented in the changelog:
在《变更日志》中有记载:
Similarly, the ordinal.rangePoints and ordinal.rangeRoundPoints methods have been replaced with a new subclass of ordinal scale: point scales. The following code in 3.x:
同样,顺序。rangePoints和顺序。距离点方法已经被一个新的序数标度子类所取代:点标度。3.x中的代码如下:
var x = d3.scale.ordinal() .domain(["a", "b", "c"]) .rangePoints([0, width]);
Is equivalent to this in 4.0:
与4.0版本相当:
var x = d3.scalePoint() .domain(["a", "b", "c"]) .range([0, width]);
Therefore, the scale you need here is scalePoint:
因此,这里需要的量表是scalePoint:
Point scales are a variant of band scales with the bandwidth fixed to zero. Point scales are typically used for scatterplots with an ordinal or categorical dimension.
点比例尺是带宽固定为零的带刻度的一种变体。点标度通常用于具有顺序或类别维度的散点图。
Thus, change your scale to:
因此,将您的比例更改为:
var x = scalePoint()
.range([0, width])
.padding(.1);
Pay attention to the padding
: in a point scale, range
accepts only the range array, not the padding anymore.
注意填充:在点比例尺中,范围只接受范围数组,不再接受填充。
#1
12
In D3 v4, two new scales were created: scaleBand
and scalePoint
, which now have some of the features that scale.ordinal
had in version 3 (among them rangePoints
).
在D3 v4中,创建了两个新的scale: scaleBand和scalePoint,它们现在具有一些可伸缩的特性。序号在第三版中(其中有距离点)。
It's documented in the changelog:
在《变更日志》中有记载:
Similarly, the ordinal.rangePoints and ordinal.rangeRoundPoints methods have been replaced with a new subclass of ordinal scale: point scales. The following code in 3.x:
同样,顺序。rangePoints和顺序。距离点方法已经被一个新的序数标度子类所取代:点标度。3.x中的代码如下:
var x = d3.scale.ordinal() .domain(["a", "b", "c"]) .rangePoints([0, width]);
Is equivalent to this in 4.0:
与4.0版本相当:
var x = d3.scalePoint() .domain(["a", "b", "c"]) .range([0, width]);
Therefore, the scale you need here is scalePoint:
因此,这里需要的量表是scalePoint:
Point scales are a variant of band scales with the bandwidth fixed to zero. Point scales are typically used for scatterplots with an ordinal or categorical dimension.
点比例尺是带宽固定为零的带刻度的一种变体。点标度通常用于具有顺序或类别维度的散点图。
Thus, change your scale to:
因此,将您的比例更改为:
var x = scalePoint()
.range([0, width])
.padding(.1);
Pay attention to the padding
: in a point scale, range
accepts only the range array, not the padding anymore.
注意填充:在点比例尺中,范围只接受范围数组,不再接受填充。