I believe you just need to call parseInt when you set the values, because
they're coming into the data table as strings.

Here's your code in a fiddle with the parseInt calls added:
http://jsfiddle.net/TJvLc/4/

Let me know if you need any more help,
Tom

On Tue, Apr 9, 2013 at 9:44 PM, OffensivelyBad <[email protected]>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 Chart 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-chart-api?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Chart 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-chart-api?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to