Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D3.js scaleOrdinal doesn't support rangeRoundBands method

Tags:

d3.js

Getting error on rangeRoundBands method when using D3.js version 4 for ordinal scale. Below is the example in D3.js version 3.

https://bl.ocks.org/mbostock/7440840

However with version 4 below code throws an error.

var x = d3.scaleOrdinal()
.domain(data.map(function(d) { return d.name; }))
.rangeRoundBands([0, width], 0.1);
like image 417
msapkal Avatar asked Aug 26 '16 07:08

msapkal


Video Answer


1 Answers

Instead of this:

var x = d3.scaleOrdinal()
.domain(data.map(function(d) { return d.name; }))
.rangeRoundBands([0, width], 0.1);

In d3 v4

It should have been:

var x = d3.scaleBand()
    .rangeRound([0, width])
    .padding(0.1);

working code here

like image 180
Cyril Cherian Avatar answered Oct 04 '22 14:10

Cyril Cherian