最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - d3.js t.map is not a function - Stack Overflow

programmeradmin1浏览0评论

Hope somebody can help me out because I can't find any reference about this error.

I was working on this piece of code:

var xMin = d3.min(data, function(d) { return d.value; });
var xMax = d3.max(data, function(d) { return d.value; });

if (0 > xMin & 0 > xMax) {
  xMax = 0;
}

if (0 < xMin & 0 < xMax) { 
  xMin = 0;
}

x.domain(xMin, xMax).nice();
y.domain(data.map(function(d) { return d.label; }));

but I must have made some mistake cause now the loading blocks with the error message below in the web console:

"TypeError: t.map is not a function @ .v3.min.js:2

Hope somebody can help me out because I can't find any reference about this error.

I was working on this piece of code:

var xMin = d3.min(data, function(d) { return d.value; });
var xMax = d3.max(data, function(d) { return d.value; });

if (0 > xMin & 0 > xMax) {
  xMax = 0;
}

if (0 < xMin & 0 < xMax) { 
  xMin = 0;
}

x.domain(xMin, xMax).nice();
y.domain(data.map(function(d) { return d.label; }));

but I must have made some mistake cause now the loading blocks with the error message below in the web console:

"TypeError: t.map is not a function @ http://d3js.org/d3.v3.min.js:2

Share Improve this question edited May 27, 2016 at 13:21 fredmaggiowski 2,2483 gold badges28 silver badges44 bronze badges asked Jun 13, 2013 at 13:56 mirbamirba 1391 gold badge2 silver badges10 bronze badges 3
  • Should be x.domain([xMin, xMax]).nice(). – Lars Kotthoff Commented Jun 13, 2013 at 13:58
  • thank you! That was exactly the problem! – mirba Commented Jun 13, 2013 at 14:12
  • 1 Added as answer for reference. – Lars Kotthoff Commented Jun 13, 2013 at 14:22
Add a comment  | 

2 Answers 2

Reset to default 14

.domain() takes an array as argument, i.e.

x.domain(xMin, xMax).nice();

should be

x.domain([xMin, xMax]).nice();

I had this error when I switched the mock data from an example.

   var dataset = d3.layout.stack()(["CountPending", "CountDenied"].map(function (type) {
            return data.map(function (d) {
                return { x: d.Name, y: +d[type] };
            });
        }));

In my dataset the example data was using ["pending","denied"] while my real data used the following keys ["CountPending", "CountDenied"]

Use the right keys!

While this might not help the OP, I hope it helps someone.

发布评论

评论列表(0)

  1. 暂无评论