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

查看:16
本文介绍了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);

从 D3 4.0 版开始,d3.scale.ordinal() 现在是 d3.scaleOrdinal,而 rangeRoundBands 似乎已经消失了.>

As of D3 version 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] 
}

与此代码(来自 Mike Bostock 的 条形图示例)等效的 D3 v4 是什么?

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 被移动到新的 Band 比例:

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天全站免登陆