我有一个Json文件,表示带有节点和链接的图形。节点id是整数但非常大。 例如。 JSON:
"directed": false,
"graph": {},
"nodes": [
{
"parity": 0,
"degree": 17,
"fraud_id": 1,
"component": -9202453918824477682,
"community": 0,
"fraudind": 1,
"betweenness": 0.0,
"id": 589139887331672165
},
{
"parity": 0,
"degree": 21,
"fraud_id": 1,
"component": -9202453918824477682,
"community": 1,
"fraudind": 1,
"betweenness": 0.17316017316017315,
"id": 6847927546904557618
},
当我尝试使用d3.json()解析数据时,数据不会保持精度。因此,上述节点的id变为589139887331672000
,删除最后三位数。以下例如。说明了这一点:
function myFunc(data) {
console.log(data);
}
d3.json(strUser, function (error, graph) {
myFunc(graph);
force1.nodes(graph.nodes)
.links(graph.links)
.start();
var link = svg_g1.selectAll(".link")
.data(graph.links)
.enter().append("line")
.attr("class", "link")
.style("stroke", function (d) {
return color2(d.edge_property);
})
var node = svg_g1.selectAll(".node")
.data(graph.nodes)
.enter().append("circle")
.attr("class", "node")
.attr("r", 5) // radius
.style("fill", function (d) {
return color(d.fraudind);
})
.attr("id", function (d) {
return "c" + d.id;
})
.call(force1.drag)
}
在上面,"c"+d.id
没有给出json的确切ID,而是舍入数字。如何确保d3.json读取的数据保持精度或读取为字符串而不是整数?