将javascript参数传递到D3

将javascript参数传递到D3,javascript,d3.js,Javascript,D3.js,我目前正在D3中制作散点图矩阵。我的数据点结构如下所示: function plot(p) { var cell = d3.select(this); x.domain(domainByTrait[p.x]); y.domain(domainByTrait[p.y]); // Data points cell.selectAll("circle") .data(data) .enter().app

我目前正在D3中制作散点图矩阵。我的数据点结构如下所示:

      function plot(p) {
      var cell = d3.select(this);

      x.domain(domainByTrait[p.x]);
      y.domain(domainByTrait[p.y]);

      // Data points
      cell.selectAll("circle")
      .data(data)
      .enter().append("circle")
      .attr("cx", function (d) { return x(d[p.x]); })
      .attr("cy", function (d) { return y(d[p.y]); })
      .attr("r", 3)
      .style("fill", function (d) { return color(d.species); });
  }
我还有一个javascript函数:

      function create(columnsplit) {

      cell = svg.selectAll(".cell")
      .data(cross(traits, traits))
      .enter().append("g")
      .attr("class", "cell")
      .attr("transform", function (d) { return "translate(" + (n - d.i - 1) * size + "," + d.j * size + ")"; })
      .each(plot);

      cell.call(brush);

  }
指定绘图的位置。但是,我想用create函数中的ColumnSpilt参数替换硬编码的d.species(除非d.species不能像我最初认为的那样工作)。我到底要怎么做

以下是我如何创建数据d的特征,据我所知:

domainByTrait = {},
      traits = d3.keys(data[0]).filter(function (d) { return d !== columnsplit; }),
      n = traits.length;

traits.forEach(function (trait) {
              domainByTrait[trait] = d3.extent(data, function (d) { return d[trait]; });
          });
我将此用作我的模板:


谢谢

如果我理解,您希望访问名为“ColumnSpilt”的值的属性。为此,只需使用索引器符号来访问属性:

d[columnsplit]

换句话说,
d.species
语法相当于
d[“species”]
()

我想用create函数中的columnspilt参数替换硬编码的d.species
你的确切意思是什么?为什么不能这样做呢?我需要将其设置为d。“ColumnSpilt中定义的任何列”,但因为“.”使其成为一个文字属性,我不能直接转到d.ColumnSpilt,因为这样它将查看当前数据并查找名为ColumnSpilt的属性。