[英]d3js: d3.csv and it's data disappears
I use this code: 我使用以下代码:
var map_json; // in global scope
var map;
...
function get_data() {
map_json = d3.json("data/russia_1e_7sr.json", function (e, d) {
map = d;
});
// ... draw map
}
If I debug this code then I see the result. 如果我调试此代码,则会看到结果。 If I close debugger and then refresh the page, the results disappears.
如果关闭调试器,然后刷新页面,结果将消失。
I suggest that something happening with object's memory. 我建议对象的内存发生某些事情。 But what?
但是呢
What is the right way to get data with d3? 用d3获取数据的正确方法是什么? Yes, I see an examples such this:
是的,我看到这样的示例:
d3.csv("file.csv", function(e,d) {
// ... use d
// all things processed inside this function
}
What if I want to load several data parts from different sources? 如果要从不同来源加载多个数据部分怎么办?
You need to shift the draw map bit: 您需要将绘制图位移动:
var map_json; // in global scope
...
function get_data() {
map_json = d3.json("data/russia_1e_7sr.json", function (e, d) {
var map;= d;
// ... draw map
});
}
map
won't be populated yet where you have it. map
不会在您拥有的位置进行填充。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.