当我想用Google图表库绘制一些温度图时,我正在PHP中构建一个数组,以将其编码为JSON,如
https://developers.google.com/chart/interactive/docs/reference#methods
“ dataTable ['cols']”的第一项是x轴。然后,我想一一添加更多的行。
这有效:
$dataTable = array();
$dataTable['cols'] = array(
array('id' => 'time_axis', 'label' => 'Time', 'type' => 'datetime')
);
foreach($sensors as $id => $description) {
//Entries in $sensors are from a database
$column = array('id' => $id, 'label' => $description, 'type' => 'number');
array_push($dataTable['cols'],$column);
}
这不是(500服务器错误):
$dataTable = array();
$dataTable['cols'] = array(
array('id' => 'time_axis', 'label' => 'Time', 'type' => 'datetime')
);
foreach($sensors as $id => $description) {
//Entries in $sensors are from a database
$column = array('id' => $id, 'label' => $description, 'type' => 'number');
$dataTable['cols'][] = $column;
}
当我在这里阅读接受的答案时
对,它应该是等效的。
只需尝试以相同的方式添加x轴即可:
$dataTable['cols'][] = array('id' => 'time_axis', 'label' => 'Time', 'type' => 'datetime');
并且不要忘记$
前面的dataTable
!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句