首页 > 解决方案 > Uncaught SyntaxError: Unexpected identifier - 尝试理解 D3 js

问题描述

我尝试使此代码有效(D3.js)。基本上,此代码呈现存储在 json 文件中的图形。

但是有一些我不明白的东西可能很明显,但我无法理解。

我有这部分代码

color = {
    const scale = d3.scaleOrdinal(d3.schemeCategory10);
    return d => scale(d.group);
}

这会引发以下错误:

':' expected.

{
    "resource": "",
    "owner": "typescript",
    "code": "1005",
    "severity": 8,
    "message": "':' expected.",
    "source": "ts",
    "startLineNumber": 5,
    "startColumn": 11,
    "endLineNumber": 5,
    "endColumn": 16
}

此颜色用于这部分代码:

const node = svg.append("g")
        .attr("stroke", "#fff")
        .attr("stroke-width", 1.5)
        .selectAll("circle")
        .data(nodes)
        .join("circle")
        .attr("r", 5)
        .attr("fill", color)
        .call(drag(simulation));

我敢肯定,这与Javascript有关。你有什么线索可以让我理解吗?

谢谢

标签: javascriptd3.jsobservablehq

解决方案


推荐阅读