我遵循了zoomcharts文档中关于如何替换NetChart上的数据的示例。当我在图表实例上调用replaceData((时,什么都没有发生,什么都不显示,也没有显示错误。
但当我将数据设置为预加载(如下所示(时,网络就会出现。
chart = new zc.NetChart({
data: [
{
preloaded: {
nodes: [Array of nodes],
links: [Array of links],
},
},
],
...
})
当我访问";替换数据";例如,我看到了一个JSFiddle;replaceData(("功能,它似乎对我来说很好。请参阅此处:https://jsfiddle.net/egd1kj9x/
也许你可以复制这个例子,然后从中找出这个例子和你想做的有什么不同?
以下是完整的示例:
var randomSeed = 10; // this can be changed to generate different data sets
function getRandomNumber() {
var x = Math.sin(randomSeed++) * 10000;
return x - Math.floor(x);
}
var nextNodeId = 0;
chart = null;
function buildData() {
var nodes = [];
var links = [];
var i;
var numNodes = 10;
for (i = 0; i < numNodes; i++) {
nodes.push({ "id": i, "loaded": true });
}
//make some random links
for (i = 0; i < 10; i++) {
var from = Math.floor(getRandomNumber() * numNodes);
var to = Math.floor(getRandomNumber() * numNodes);
links.push({ "id": i + "_" + from + "_" + to, "from": from, "to": to });
}
chart.replaceData({ "nodes": nodes, "links": links });
}
chart = new NetChart({
style: {
node: {
display: "text",
fillColor: "rgba(47,195,47,0.9)",
},
link: {
fillColor: "rgba(86,185,247,0.4)"
}
},
container: document.getElementById("demo"),
area: { height: 350 }
});
buildData();
var intervalHandle = setInterval(buildData, 2400);
function disposeDemo() {
window.clearInterval(intervalHandle);
disposeDemo = null;
intervalHandle = null;
}