对于Visualization API的DataTable构造函数,您的数据结构不正确。
对于列正确的格式是列对象的数组,其中每个对象具有
type(强制), ,
label,
id和
p(所有可选)属性。
type是可能的值的字符串
string,
number,
boolean,
date,
datetime,和
timeofday。
label并且
id是字符串。
p是列属性的对象。
行的正确格式是行对象的数组,其中每个对象都有
c和
p属性。
c是单元格对象的数组。
p是行属性的对象。单元格对象具有
v,
f和
p属性,其中
v是单元格的值,是单元格
f的字符串格式的值,并且
p是单元格属性的对象。
所有属性对象支持的属性都取决于您所绘制的图表类型。
使用PHP的
json_enpre功能,将关联数组转换为对象,将非关联数组转换为数组。表的适当结构应如下所示:
$columns = array( array('type' => 'string', 'label' => 'x'), array('type' => 'number', 'label' => 'values'), // each interval should have its own unique id, // but leaving them the same won't break anything for your chart as-is array('type' => 'number', 'id' => 'i1', 'p' => array('role' => 'interval')), array('type' => 'number', 'id' => 'i1', 'p' => array('role' => 'interval')), array('type' => 'number', 'label' => 'OtherValues'), array('type' => 'number', 'id' => 'i1', 'p' => array('role' => 'interval')), array('type' => 'number', 'id' => 'i1', 'p' => array('role' => 'interval')));$test = array( array('c' => array( array('v' => 'a'), array('v' => 100), array('v' => 90), array('v' => 150), array('v' => 15), array('v' => 10), array('v' => 20) )), // etc);$table['cols'] = $columns;$table['rows'] = $test;


