D3 4.0 rangeRoundBands等效? [英] D3 4.0 rangeRoundBands equivalent?

查看:832
本文介绍了D3 4.0 rangeRoundBands等效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到很多D3代码,有这样的:

I see a lot of D3 code that has something like this:

var x = d3.scale.ordinal()
  .rangeRoundBands([0, width], .1);

自D4 4.0起 d3.scale.ordinal()现在 d3.scaleOrdinal rangeRoundBands 似乎已经不见了。

As of D4 4.0 d3.scale.ordinal() is now d3.scaleOrdinal and rangeRoundBands seems to be gone.

> d3.scaleOrdinal()

 { [Function: scale]
 domain: [Function],
 range: [Function],
 unknown: [Function],
 copy: [Function] }

D3 v4等效于什么Bostock的条形图示例)是?

What would the D3 v4 equivalent of this code (from Mike Bostock's bar chart example) be?

var x = d3.scale.ordinal()
  .rangeRoundBands([0, width], .1);


推荐答案

在D3 4.x rangeRoundBands 已移至新的 范围:

In D3 4.x rangeRoundBands was moved to the new Band scale:

d3.scaleBand()
    .range([range])
    .round([round]);

这相当于:

d3.scaleBand()
    .rangeRound([range]);

以下是API: https://github.com/d3/d3-scale#band-scales

这篇关于D3 4.0 rangeRoundBands等效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆