Javascript 未捕获的语法错误:意外标记。D3工具提示

Javascript 未捕获的语法错误:意外标记。D3工具提示,javascript,d3.js,Javascript,D3.js,我遇到了这个错误。我正在尝试向d3元素添加工具提示。如果你知道我哪里出了问题,请告诉我。错误是 Uncaught SyntaxError: Unexpected token . on the .append 这是我的代码: g.selectAll("scatter-dots") .data(data) .enter().append("svg:circle") .attr("cx", function (d,i) { return x(d[0]); } ) .a

我遇到了这个错误。我正在尝试向d3元素添加工具提示。如果你知道我哪里出了问题,请告诉我。错误是

Uncaught SyntaxError: Unexpected token . on the .append
这是我的代码:

g.selectAll("scatter-dots")
  .data(data)
  .enter().append("svg:circle")
      .attr("cx", function (d,i) { return x(d[0]); } )
      .attr("cy", function (d) { return y(d[1]); } )
      .attr("r", 8);
      // Here we add an SVG title element the contents of which is effectively rendered in a tooltip
      .append("svg:title")
        .text(function(d, i) { return "My color is " + d[2]; });

正如错误所说,您有一个语法错误

.attr("r", 8);
您不能拥有
然后追加<代码>实际上结束了语句。
这是正确的代码

g.selectAll("scatter-dots")
  .data(data)
  .enter().append("svg:circle")
      .attr("cx", function (d,i) { return x(d[0]); } )
      .attr("cy", function (d) { return y(d[1]); } )
      .attr("r", 8)
      // Here we add an SVG title element the contents of which is effectively rendered in a tooltip
      .append("svg:title")
        .text(function(d, i) { return "My color is " + d[2]; });

注意:我想您的选择也有错误,在
g.selectAll(“散点”)
散点
指的是什么?
id
。如果它是
,那么它必须是
。散布点
,或者如果它是
id
,那么它必须是
。\n散布点

在设置
.attr(“r”,8)
结束语句后有一个分号。因此,关于下一行以点开始的错误。