在Google图表中,#0轴的数据列不能是字符串错误 [英] Data column(s) for axis #0 cannot be of type string error in google chart
本文介绍了在Google图表中,#0轴的数据列不能是字符串错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在从数据库获取数据后,
$ colarray =阵列(阵列( ID=> 中, 标签=> 中参数userid, 图案=> 中, 类型=> 中号),阵列( ID => 中, 标签=> 中的名称, 图案=> 中, 类型=> 中的字符串));
$ final = array(); ($ i = 0; $ i <$行; $ i ++)
{
$ id [$ i] = pg_fetch_result($ res1,$ i,'id');
$ name [$ i] = pg_fetch_result($ res1,$ i,'name');
$ prefinal [$ i] = array(c=> array(array(v=> $ name [$ i]),array(v=> $ name [$ i ])));
array_push($ final,$ prefinal [$ i]);
}
$表['cols'] = $ colarray;
$ table ['rows'] = $ final;
echo json_encode($ table);
My Output Json:
{
cols:[
{id:,label:userid,pattern: ,type:number},
{id:,label:name,pattern:,type:string}
] ,
rows:[
{c:[{v:101},{v:Aircel}]},
{c :[{v:102},{v:Srini}]},
{c:[{v:103},{v:泰米尔语}}},
{c:[{v:104},{v:Thiyagu}]},
{c:[ v:105},{v:Vasan}]},
{c:[{v:107},{v:Senthil}] },
{c:[{v:108},{v:Sri}]},
{c:[{v: 109},{v:Docomo}]},
{c:[{v:106},{v:Innodea}] b]
}
如何解决这个问题?
p>我只是浪费了30分钟的时间,出现了相反的问题...
你的输出json应该看起来像例如: -
{
cols:[
{id:, label:userid,pattern:,type:number},
{id:,label:name,pattern:, type:string}
],
rows:[
{c:[{v:101},{v:Aircel}} ]},
{c:[{v:102},{v:Srini}]},
{c:[{v:103} ,{v:Tamil}]},
{c:[{v:104},{v:Thiyagu}]},
{c :[{v:105},{v:Vasan}]},
{c:[{v:107},{v:Senthil}} ]},
{c:[{v:108},{v:Sri}]},
{c:[{v:109} ,{v:Docomo}]},
{c:[{v:106},{v:Innodea}]}
]
}
I tried to populate google chart datatable in server side using PHP.I got JSON file properply, but the Chart not display in client Application. I got error-Data column(s) for axis #0 cannot be of type string . My coding is below here.
After fetching data from database,
$colarray=array(array("id"=>"","label"=>"userid","pattern"=>"","type"=>"number"),array("id"=>"","label"=>"name","pattern"=>"","type"=>"string"));
$final=array();
for($i=0;$i<$rows;$i++)
{
$id[$i]=pg_fetch_result($res1,$i,'id');
$name[$i]=pg_fetch_result($res1,$i,'name');
$prefinal[$i]=array("c"=>array(array("v"=>$name[$i]),array("v"=>$name[$i])));
array_push($final,$prefinal[$i]);
}
$table['cols']=$colarray;
$table['rows']=$final;
echo json_encode($table);
My Output Json:
{
"cols":[
{"id":"","label":"userid","pattern":"","type":"number"},
{"id":"","label":"name","pattern":"","type":"string"}
],
"rows":[
{"c":[{"v":"101"},{"v":"Aircel"}]},
{"c":[{"v":"102"},{"v":"Srini"}]},
{"c":[{"v":"103"},{"v":"Tamil"}]},
{"c":[{"v":"104"},{"v":"Thiyagu"}]},
{"c":[{"v":"105"},{"v":"Vasan"}]},
{"c":[{"v":"107"},{"v":"Senthil"}]},
{"c":[{"v":"108"},{"v":"Sri"}]},
{"c":[{"v":"109"},{"v":"Docomo"}]},
{"c":[{"v":"106"},{"v":"Innodea"}]}
]
}
How to solve this issue?
解决方案
You specify type of userid as number... but pass string.. thats causing the problem.
I just wasted 30 mins with the opposite problem ...
Your output json should look like :-
{
"cols":[
{"id":"","label":"userid","pattern":"","type":"number"},
{"id":"","label":"name","pattern":"","type":"string"}
],
"rows":[
{"c":[{"v":101},{"v":"Aircel"}]},
{"c":[{"v":102},{"v":"Srini"}]},
{"c":[{"v":103},{"v":"Tamil"}]},
{"c":[{"v":104},{"v":"Thiyagu"}]},
{"c":[{"v":105},{"v":"Vasan"}]},
{"c":[{"v":107},{"v":"Senthil"}]},
{"c":[{"v":108},{"v":"Sri"}]},
{"c":[{"v":109},{"v":"Docomo"}]},
{"c":[{"v":106},{"v":"Innodea"}]}
]
}
这篇关于在Google图表中,#0轴的数据列不能是字符串错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文