[Chicago-talk] using Google visualization

Joel Limardo joel.limardo at forwardphase.com
Tue Aug 3 13:21:55 PDT 2010


I like the idea of the JSON having the version information, signature, etc.
is good but I including the google.visualization.Query.setResponse may make
your solution a bit fragile. What if the Google folks decide to change their
API so you are supposed to do something like this:

google.visualization.DOSOMETHINGELSE(...)

?  Your code will probably break. I look at JSON as being an abbreviated
version of XML so anything that would not go into an XML document I probably
would not want in my JSON either.

On Tue, Aug 3, 2010 at 3:04 PM, Jay Strauss <me at heyjay.com> wrote:

> Hi Joel,
>
> thanks for the example and info.  I can kinda read what you are doing
> (I've never programmed in javascript).  Basically you are calling a
> URL that delivers a JSON string, then you parse it in your Javascript
> and load the data table with the parsed info.
>
> Looking at the example in:
>
> http://code.google.com/apis/ajax/playground/?type=visualization#data_source_request
>
> I think though if one was to send back the properly formated results, like:
>
> http://spreadsheets.google.com/tq?key=pCQbetd-CptGXxxQIG7VFIQ&range=B1:D11&pub=1
>
> with the proper header:
>
> google.visualization.Query.setResponse({version:'0.6',status:'ok',sig:'1068688546',table:
> bunch 'o JSON..
>
> I can shove it right into the datatable without parsing like:
>
> var data = response.getDataTable();
>
> I'm going to play with this some more.
>
> Thanks
> Jay
>
> On Tue, Aug 3, 2010 at 1:41 PM, Joel Limardo
> <joel.limardo at forwardphase.com> wrote:
> > 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:
> > data.addRows(myJSONObj.actualData);
> > The JSON looks like this:
> > {
> >   "columns":["Sales","SalesValue"],
> >   "actualData":[
> >                  ["2001",100],
> >                  ["2002",200],
> >                  ["2003",300],
> >                  ["2004",400],
> >                  ["2005",800]
> >               ]
> > }
> > Again, the actual example is
> > here:
> http://www.bixchange.com/cgi-bin/bixchange/bixchange.cgi?pom=test-gsapi;iid=0001
> > 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
> >
> >
> >
> >
> > _______________________________________________
> > Chicago-talk mailing list
> > Chicago-talk at pm.org
> > http://mail.pm.org/mailman/listinfo/chicago-talk
> >
> _______________________________________________
> 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/071cbbf7/attachment.html>


More information about the Chicago-talk mailing list