【发布时间】:2015-03-09 16:05:33
【问题描述】:
我正在绘制一个Google Charts Timeline 绘图,显示位于 MySQL 数据库表中的多个任务的持续时间。使用 PHP 有多种方法可以检索和存储它,例如作为二维数组。但是,有没有办法通过dataTable.addrows() 方法以 Google Charts Timeline 可以处理的方式传递这样一个数组(或其他容易创建的包含对象的数据)?
或者如果我应该将其描述为示例:
function drawChart() {
// Nothing to see here, move along now...
var container = document.getElementById('timeline');
var chart = new google.visualization.Timeline(container);
var dataTable = new google.visualization.DataTable();
// The column heading can be fixed or variable, this doesnt matter.
dataTable.addColumn({ type: 'string', id: 'Opgave ID' });
dataTable.addColumn({ type: 'string', id: 'Opgavetitel' });
dataTable.addColumn({ type: 'date', id: 'Start' });
dataTable.addColumn({ type: 'date', id: 'End' });
/* I would like to replace the fixed input of dataTable.addRows, with a
*variable input, for instance a 2-dimensional PHP-array.
*/
dataTable.addRows([
[ '1', 'Some task', new Date(2015, 3, 9), new Date(2015, 3, 23) ],
[ '2', 'Another task', new Date(2015, 3, 13), new Date(2015, 3, 20) ],
[ '3', 'A different task', new Date(2015, 3, 16), new Date(2015, 3, 30) ]]);
// No questions for any of this
var options = {
timeline: {showRowLabels: false, singleColor: '#8d8'}
};
chart.draw(dataTable, options);
}
【问题讨论】:
-
看来我的问题不是一般语法,而是如何在 PHP 中格式化日期以使其在
json_encode之后成为正确的语法... -
由于问题只是日期格式,我在 StackOverflow 上发了一篇新帖子,专门解决了这个问题。希望这将使回复者和其他有相同问题的人更容易。见:stackoverflow.com/questions/29004501/…
-
我有同样的问题,但日期和时间。我在这个和下一个你的帖子stackoverflow.com/questions/29004501/… 中尝试了一些建议的解决方案,但它们不起作用。你找到解决这个问题的方法了吗?如果是,您可以在这里分享答案吗?
-
有效的解决方案是答案 - stackoverflow.com/questions/36233412/…
标签: javascript php mysql arrays google-visualization