Thanks, that worked. This one had me perplexed.

On Wednesday, April 10, 2013 1:30:26 AM UTC-4, asgallant wrote:
>
> The problem lies with the json.hits.hits[index]._source.routes values: 
> they are stored as strings in the JSON, and you input them as strings into 
> the DataTable, even though the column type is "number".  I'm not sure 
> whether this qualifies as a bug in the API or not, but when you enter 
> numbers as strings, the charts behave weirdly.  You can solve this problem 
> in one of two ways: 1) correct the JSON to store the values as numbers 
> instead of strings, or 2) use the parseInt function on the data as you pull 
> it from JSON: 
>
> "v": parseInt(json.hits.hits[i]._source.routes)
>
> On Tuesday, April 9, 2013 9:45:10 PM UTC-4, OffensivelyBad wrote:
>>
>> Hi, I'm trying to populate a Google Pie Chart however the chart is 
>> populated with "other" when my data seems to be fine.  Could you please 
>> take a look at (and run) my code and let me know what I may be doing 
>> wrongly?
>>
>> Here is an HTML document you can save and run to see what I mean:
>>
>> <html>
>>
>>   <head>
>>
>>     <script type="text/javascript" src="https://www.google.com/jsapi
>> "></script>
>>
>>     <script type="text/javascript" src="
>> http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
>> "></script>
>>
>>     <script type="text/javascript">
>>
>>     
>>
>>      google.load('visualization', '1', {'packages':['corechart']});
>>
>>       
>>
>>      google.setOnLoadCallback(drawChart);
>>
>>       
>>
>>    function drawChart() {
>>
>>       var json = {
>>
>>   "took" : 1,
>>
>>   "timed_out" : false,
>>
>>   "_shards" : {
>>
>>     "total" : 5,
>>
>>     "successful" : 5,
>>
>>     "failed" : 0
>>
>>   },
>>
>>   "hits" : {
>>
>>     "total" : 7,
>>
>>     "max_score" : 1.0,
>>
>>     "hits" : [ {
>>
>>       "_index" : "wcs",
>>
>>       "_type" : "routes",
>>
>>       "_id" : "4",
>>
>>       "_score" : 1.0, "_source" : {"lane":"M04","routes":"102"}
>>
>>     }, {
>>
>>       "_index" : "wcs",
>>
>>       "_type" : "routes",
>>
>>       "_id" : "5",
>>
>>       "_score" : 1.0, "_source" : {"lane":"M03","routes":"143"}
>>
>>     }, {
>>
>>       "_index" : "wcs",
>>
>>       "_type" : "routes",
>>
>>       "_id" : "1",
>>
>>       "_score" : 1.0, "_source" : {"lane":"M07","routes":"80"}
>>
>>     }, {
>>
>>       "_index" : "wcs",
>>
>>       "_type" : "routes",
>>
>>       "_id" : "6",
>>
>>       "_score" : 1.0, "_source" : {"lane":"M02","routes":"157"}
>>
>>     }, {
>>
>>       "_index" : "wcs",
>>
>>       "_type" : "routes",
>>
>>       "_id" : "2",
>>
>>       "_score" : 1.0, "_source" : {"lane":"M06","routes":"101"}
>>
>>     }, {
>>
>>       "_index" : "wcs",
>>
>>       "_type" : "routes",
>>
>>       "_id" : "7",
>>
>>       "_score" : 1.0, "_source" : {"lane":"M01","routes":"105"}
>>
>>     }, {
>>
>>       "_index" : "wcs",
>>
>>       "_type" : "routes",
>>
>>       "_id" : "3",
>>
>>       "_score" : 1.0, "_source" : {"lane":"M05","routes":"160"}
>>
>>     } ]
>>
>>   }
>>
>> }
>>
>>    
>>
>> var jdata = {};
>>
>> jdata.cols = [
>>
>>     {
>>
>>         "id": "",
>>
>>         "label": "Lane",
>>
>>         "type": "string"
>>
>>     },
>>
>>     {
>>
>>         "id": "",
>>
>>         "label": "Routes",
>>
>>         "type":"number"
>>
>>     }
>>
>> ];
>>
>> jdata.rows = [
>>
>>     {
>>
>>         "c": [
>>
>>             {
>>
>>                 "v": json.hits.hits[0]._source.lane
>>
>>             },
>>
>>             {
>>
>>                 "v": json.hits.hits[0]._source.routes
>>
>>             }
>>
>>         ]
>>
>>     }
>>
>> ];
>>
>> /*
>>
>> jdata.rows.push(
>>
>> {
>>
>> "c": [
>>
>> {
>>
>> "v": json.hits.hits[6]._source.lane
>>
>> },
>>
>> {
>>
>> "v": json.hits.hits[6]._source.routes
>>
>> }
>>
>> ]
>>
>> });*/
>>
>>
>> //loop through remaining results
>>
>>
>> if (json.hits.hits.length > 1) 
>>
>> {
>>
>> for(i=1;i<json.hits.hits.length; i++)
>>
>> {
>>
>> jdata.rows.push({
>>
>> "c": [
>>
>> {
>>
>> "v": json.hits.hits[i]._source.lane
>>
>> },
>>
>> {
>>
>> "v": json.hits.hits[i]._source.routes
>>
>> }
>>
>> ]
>>
>> });
>>
>> };
>>
>> };
>>
>>
>>      var data = new google.visualization.DataTable(jdata);
>>
>>
>>       var chart = new 
>> google.visualization.PieChart(document.getElementById('piechart_div'));
>>
>>      chart.draw(data, {is3D: true, title: 'Multi Routes per Lane', width: 
>> 600, height: 440});
>>
>>     }
>>
>>     </script>
>>
>> </head>
>>
>> <body>
>>
>> <div id="piechart_div"> </div>
>>
>>  </body>
>>
>> </html>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at 
http://groups.google.com/group/google-visualization-api?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to