我想根据此示例重现直方图 http://bl.ocks.org/mbostock/3048450但从sql表中读取输入数据。 将数据读取到“值”是可行的,但只有当我从 SQL 读取数据后发出警报时,条形图才会显示在浏览器中。
我假设 svg 是在读取所有数据之前渲染的?
var values = [];
var counter = 0;
d3.json("php/data2.php", function(error, arrw) {
arrw.forEach(function(d) {
values.push(parseFloat(arrw[counter]["close"]));
counter++;
});
});
alert(); // without this alert the bars are not displayed in the svg
最佳答案
尝试使用 D3 库 queue()
来计时更新。
所以类似:
queue()
.defer(d3.json, "php/data2.php")
.await(ready);
function ready(error, arrw) {
//now you can use the data set in your general update paradigm
//and did not have to wait the data to load sequentially
arrw.forEach(function(d) {
values.push(parseFloat(arrw[counter]["close"]));
counter++;
});
}
关于php - 为什么从mysql数据库读取数据,直方图不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26326426/