Php 使用数据库中的JSON数据进行D3行转换
我跟着迈克·波士顿的导游走 我想要的是一条像我发现的小提琴一样移动的线 我的问题是它很容易处理来自csv或其他文件的格式化静态数据 但我通过php从mssql数据库获取数据,并将其存储在变量中Php 使用数据库中的JSON数据进行D3行转换,php,sql,json,d3.js,transition,Php,Sql,Json,D3.js,Transition,我跟着迈克·波士顿的导游走 我想要的是一条像我发现的小提琴一样移动的线 我的问题是它很容易处理来自csv或其他文件的格式化静态数据 但我通过php从mssql数据库获取数据,并将其存储在变量中 // Get the data <php php echo "data=" .$json_data.";" ?> data.forEach(function(d) { d.Datum = parseDate(d.Datum); d.Temp = +d.Temp; }) 我在我想要的时间间
// Get the data
<php php echo "data=" .$json_data.";" ?>
data.forEach(function(d) {
d.Datum = parseDate(d.Datum);
d.Temp = +d.Temp;
})
我在我想要的时间间隔内得到这些数据。
所以问题是如何将给定的新数据点推送到我的线图中
function next () {
return {
Datum: function(d) { return d.Datum },
Temp: function(d) { return d.Temp }
};
}
tick();
function tick() {
transition = transition.each(function () {
// update the domains
x.domain(d3.extent(data, function(d) { return d.Datum; }));
// push a new data point onto the back
data.push(next());
// redraw the line, and slide it to the left
path.attr("d", line)
.attr("transform", null);
// slide the x-axis left, rescale the y-axis
axis.call(x.axis);
yAx.call(y.axis);
// slide the line left
path.transition()
.attr("transform", "translate(" + x - 1 + ")");
// pop the old data point off the front
data.shift();
}).transition().each("start", tick);
我的问题是如何处理json数据
function next () {
return {
Datum: function(d) { return d.Datum },
Temp: function(d) { return d.Temp }
};
}
tick();
function tick() {
transition = transition.each(function () {
// update the domains
x.domain(d3.extent(data, function(d) { return d.Datum; }));
// push a new data point onto the back
data.push(next());
// redraw the line, and slide it to the left
path.attr("d", line)
.attr("transform", null);
// slide the x-axis left, rescale the y-axis
axis.call(x.axis);
yAx.call(y.axis);
// slide the line left
path.transition()
.attr("transform", "translate(" + x - 1 + ")");
// pop the old data point off the front
data.shift();
}).transition().each("start", tick);