[Chicago-talk] using Google visualization

Joel Limardo joel.limardo at forwardphase.com
Tue Aug 3 11:41:58 PDT 2010

Perhaps you found a better solution by now but I figured I would respond
anyway for kicks.

I reworked my example to use an XMLHttp object to GET some JSON that would
do the exact same thing except it a) returns the column headers and b) it
returns the data in a single statement:


The JSON looks like this:

Again, the actual example is here:

Some problems I noticed

My original idea was to use HTML::Template to push out JSON the same way one
pushes out HTML. This didn't pan out because I wanted to format a JSON array
with a TMPL_LOOP but it wound up producing an extra comma at the end.  That
was causing a JSON parsing error in IE.  Apparently the inability to parse
an extra comma at the end of the array definition is documented on the
Google visualization website somewhere and was pretty annoying.

All in all, the code example is pretty sloppy but works.  I borrowed much of
the browser check code and I think it is rubbish so please don't copy any of
that for anything important. I also assumed that the first column would
always be text and the other columns of data would be numeric. I'm certain
that you could come up with something better.  Lastly I used an eval() in
the code to convert the server's response text to a JavaScript object. There
is some concern on the web that this may be a vulnerability so I would
research using better methods.

On Mon, Aug 2, 2010 at 3:18 PM, Jay Strauss <me at heyjay.com> wrote:

> >
> > I would imagine the JSON example is pretty much the exact same thing
> except
> > you just create a separate template to push out JSON and return this back
> to
> > a static HTML file pointing to its URL.  This is pretty elementary stuff,
> > however...perhaps I'm missing the problem here...?
> > --
> > Sincerely,
> >
> >> _______________________________________________
> > Chicago-talk mailing list
> > Chicago-talk at pm.org
> > http://mail.pm.org/mailman/listinfo/chicago-talk
> >
> So outside the fact that I'm a pretty elementary fellow, and your way
> is perfectly fine, and I was starting to think I'd need to do
> something similar, I thought based on my reading of the docs, that I
> could be one of the K00L kids.
> I thought I could have my Javascript call the data source directly.
> And there was some magic in the google javascript classes that would
> take the CVS file that is returned and stick it in the data source
> automagically.  That way my source web page that is delivered to the
> browser wouldn't be thousands of lines long of:
> data.addRows
> data.addRows
> data.addRows
> ...
> Again, its very possible (dare I say probable) I'm total incorrect
> about how this google visualization stuff works.  But it looks like
> you can do what I'm talking about if the datasource is a google
> spreadsheet.
> Thanks
> Jay
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20100803/e54446df/attachment.html>

More information about the Chicago-talk mailing list