How do I specify domain in d3.scale.ordinal() ?
问题 var W = 100; var H = 200; var data = [{v:4}, {v:8}, {v:15}, {v:16}, {v:23}, {v:42}]; var x = d3.scale.linear().domain([0, max_x]).range([0, W]); var y = d3.scale.ordinal().domain([0, 1, 2, 3, 4, 5]).rangeBands([0, H]); How do I automatically enumerate the domain of data without typing it out e.g., 0, 1, 2, 3 I have tried domain(data) , and domain([0, data.length]) , but I need all the values in between. 回答1: If you want the domain of the ordinal scale to be the indexes of your data, then use