Table sort not working for a number column

411 views
Skip to first unread message

Mike Beccaria

unread,
Feb 8, 2012, 4:25:32 PM2/8/12
to Google Chart API
I created my 1st visualization that creates a sortable table of
values. The problem is that when I sort the "Checkouts" column, they
sort like letters and not like numbers even though I specified the
column data type as a number.

Here's the table:
http://library.paulsmiths.edu/test/charts/top5visualization.html

And the json data that it queries:
http://library.paulsmiths.edu/test/charts/top5.php

Notice that that Checkouts column is a number but when you sort the
column, it doesn't sort properly:
{"cols":[{"id":"year","label":"Year","type":"number"},
{"id":"title","label":"Title","type":"string"},
{"id":"checkouts","label":"Checkouts","type":"number"}],

Sorted Copy from chart:
2011 Dog hikes in the Adirondacks : 20 trails to enjoy 9
2010 Water for elephants : a novel by Sara Gruen. 9
2010 The Eighth International Symposium on Environmenta 9
2010 Streams : their ecology and life by Colbert.E. Cu 8
2010 Introduction to permaculture by Bill Mollison wit 8
2010 Negotiation by Roy J. Lewicki, Bruce Barry, David 8
2010 Amuse-bouche : little bites that delight before th 8
2010 Billy Joe Tatum's Wild foods cookbook and field gu 8
2008 About wine by J. Patrick Henderson, Dellie Rex. 36
2011 The help by Kathryn Stockett. 18
2009 Twilight by Stephenie Meyer. 16
2011 Research design : qualitative, quantitative, and m 14
2009 Lies my teacher told me : everything your American 14
2009 Marked : a house of night novel |c P.C. Cast and 14
2008 Plows, plagues, and petroleum : how humans took co 14
2010 How the other half lives; studies among the teneme 13


Any idea how to fix this? Am I overlooking something?
Thanks,
Mike

Fons Seesink

unread,
Feb 9, 2012, 7:05:41 AM2/9/12
to google-c...@googlegroups.com
Looking at your website, I think you sorted things out

> --
> You received this message because you are subscribed to the Google Groups "Google Chart API" group.
> To post to this group, send email to google-c...@googlegroups.com.
> To unsubscribe from this group, send email to google-chart-a...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-chart-api?hl=en.
>

--

Best regards
Fons Seesink

Mike Beccaria

unread,
Feb 9, 2012, 7:48:45 AM2/9/12
to Google Chart API
Not with my browser. I checked it this morning (just now) and noted
that the numbers don't sort in order. Here's a screenshot:
http://screencast.com/t/O5Otv4fv

Notice the checkouts are supposed to be sorted from high to low but
they go from 9,8,...36,18,16.

Mike
> > For more options, visit this group athttp://groups.google.com/group/google-chart-api?hl=en.

Fons Seesink

unread,
Feb 9, 2012, 8:53:34 AM2/9/12
to google-c...@googlegroups.com
indeed, have been looking with my eyes closed it seems
in your code try and define with single ' rather than using "
{'cols':[{'id':.......'type':'number'}],

not sure but the websites explaining about the topic all use single

> For more options, visit this group at http://groups.google.com/group/google-chart-api?hl=en.

Mike Beccaria

unread,
Feb 9, 2012, 9:54:32 AM2/9/12
to Google Chart API
Thanks for your help! Unfortunately it didn't work. If I understood
you correctly, you wanted me to use "single" as the "type" for the
checkouts column. I couldn't find any mention of a "single" type but
put it in there anyway and now the table won't sort. The data is live
with "single" now as the type.

On this page:
http://code.google.com/apis/chart/interactive/docs/reference.html#DataTable

It lists a getColumnType function that does not mention a "single"
type:
Returns the type of a given column specified by the column index.
columnIndex should be a number greater than or equal to zero, and
less than the number of columns as returned by the
getNumberOfColumns() method.
The returned column type can be one of the following: 'string'
'number' 'boolean' 'date' 'datetime' 'timeofday'

I'm not gonna lie, I'm a bit stumped at the moment and hope I'm
overlooking something simple.
Thanks again,
Mike

Fons Seesink

unread,
Feb 9, 2012, 10:01:28 AM2/9/12
to google-c...@googlegroups.com
I did not want to advise you to use "single", but the single qoutes as
in ' rather than " to wrap your code in
like i placed in your ( shortened) code

{'cols':[{'id':.......'type':'number'}],

> For more options, visit this group at http://groups.google.com/group/google-chart-api?hl=en.

Mike Beccaria

unread,
Feb 9, 2012, 10:23:41 AM2/9/12
to Google Chart API
Hmm...That could be a problem.
I'm creating the json from a php object using json_encode() and
http://www.json.org/ website mentions the use of double quotes, not
single, but I figured I'd try it anyway. I did a string replace of all
double quotes with single quotes, which works (the data has single
quotes, not doubles), but then the chart doesn't show up at all.

Mike

On Feb 9, 10:01 am, Fons Seesink <fons.sees...@gmail.com> wrote:
> I did not want to advise you to use "single", but the single qoutes as
> in ' rather than " to wrap your code in
> like i placed in your ( shortened) code
> {'cols':[{'id':.......'type':'number'}],
>
>
>
>
>
>
>
>
>
> On Thu, Feb 9, 2012 at 3:54 PM, Mike Beccaria <mikebecca...@gmail.com> wrote:
> > Thanks for your help! Unfortunately it didn't work. If I understood
> > you correctly, you wanted me to use "single" as the "type" for the
> > checkouts column. I couldn't find any mention of a "single" type but
> > put it in there anyway and now the table won't sort. The data is live
> > with "single" now as the type.
>
> > On this page:
> >http://code.google.com/apis/chart/interactive/docs/reference.html#Dat...

Mike Beccaria

unread,
Feb 22, 2012, 9:30:50 AM2/22/12
to Google Chart API
Sorry for the bump. This is still not working and it looks like my
data and code are correct. Is this a bug? Any ideas?

On Feb 9, 10:23 am, Mike Beccaria <mikebecca...@gmail.com> wrote:
> Hmm...That could be a problem.
> I'm creating the json from a php object using json_encode() andhttp://www.json.org/website mentions the use of double quotes, not
> single, but I figured I'd try it anyway. I did a string replace of all
> double quotes with single quotes, which works (the data has single
> quotes, not doubles), but then the chart doesn't show up at all.
>
> Mike
>
> On Feb 9, 10:01 am, Fons Seesink <fons.sees...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I did not want to advise you to use "single", but the single qoutes as
> > in ' rather than " to wrap your code in
> > like i placed in your ( shortened) code
> > {'cols':[{'id':.......'type':'number'}],
>
> > >> On Thu, Feb 9, 2012 at 1:48 PM,MikeBeccaria<mikebecca...@gmail.com> wrote:
> > >> > Not with my browser. I checked it this morning (just now) and noted
> > >> > that the numbers don't sort in order. Here's a screenshot:
> > >> >http://screencast.com/t/O5Otv4fv
>
> > >> > Notice the checkouts are supposed to be sorted from high to low but
> > >> > they go from 9,8,...36,18,16.
>
> > >> >Mike
>
> > >> > On Feb 9, 7:05 am, Fons Seesink <fons.sees...@gmail.com> wrote:
> > >> >> Looking at your website, I think you sorted things out
>

TheCompWiz

unread,
Feb 22, 2012, 10:27:29 AM2/22/12
to google-c...@googlegroups.com
Stop using "" around your digits. In the results from your data set:
(http://library.paulsmiths.edu/test/charts/top5.php) the results
return values like: {"v":"10"} ... which means the string "10" and
not the number value "10". Adjust your php to return {"v":10} for
numeric values.

Mike Beccaria

unread,
Feb 22, 2012, 2:13:14 PM2/22/12
to Google Chart API
Worked like a champ:) Thanks!

On Feb 22, 10:27 am, TheCompWiz <thecomp...@gmail.com> wrote:
> Stop using "" around your digits.  In the results from your data set:
> (http://library.paulsmiths.edu/test/charts/top5.php) the results
> return values like: {"v":"10"}  ... which means the string "10" and
> not the number value "10".  Adjust your php to return {"v":10} for
> numeric values.
>
>
>
>
>
>
>
> On Wed, Feb 22, 2012 at 9:30 AM, Mike Beccaria <mikebecca...@gmail.com> wrote:
> > Sorry for the bump. This is still not working and it looks like my
> > data and code are correct. Is this a bug? Any ideas?
>
> > On Feb 9, 10:23 am, Mike Beccaria <mikebecca...@gmail.com> wrote:
> >> Hmm...That could be a problem.
> >> I'm creating the json from a php object using json_encode() andhttp://www.json.org/websitementions the use of double quotes, not
Reply all
Reply to author
Forward
0 new messages