I like the idea of the JSON having the version information, signature, etc. is good but I including the <span class="Apple-style-span" style="font-family: monospace; font-size: medium; white-space: pre-wrap; ">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:</span><div>
<font class="Apple-style-span" face="monospace"><span class="Apple-style-span" style="white-space: pre-wrap; font-size: medium;"><br></span></font></div><div><font class="Apple-style-span" face="monospace"><span class="Apple-style-span" style="white-space: pre-wrap; font-size: medium;">google.visualization.DOSOMETHINGELSE(...)<br>
</span></font><br></div><div>? 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.</div><div>
<br><div class="gmail_quote">On Tue, Aug 3, 2010 at 3:04 PM, Jay Strauss <span dir="ltr"><<a href="mailto:me@heyjay.com">me@heyjay.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi Joel,<br>
<br>
thanks for the example and info. I can kinda read what you are doing<br>
(I've never programmed in javascript). Basically you are calling a<br>
URL that delivers a JSON string, then you parse it in your Javascript<br>
and load the data table with the parsed info.<br>
<br>
Looking at the example in:<br>
<a href="http://code.google.com/apis/ajax/playground/?type=visualization#data_source_request" target="_blank">http://code.google.com/apis/ajax/playground/?type=visualization#data_source_request</a><br>
<br>
I think though if one was to send back the properly formated results, like:<br>
<a href="http://spreadsheets.google.com/tq?key=pCQbetd-CptGXxxQIG7VFIQ&range=B1:D11&pub=1" target="_blank">http://spreadsheets.google.com/tq?key=pCQbetd-CptGXxxQIG7VFIQ&range=B1:D11&pub=1</a><br>
<br>
with the proper header:<br>
google.visualization.Query.setResponse({version:'0.6',status:'ok',sig:'1068688546',table:<br>
bunch 'o JSON..<br>
<br>
I can shove it right into the datatable without parsing like:<br>
<br>
var data = response.getDataTable();<br>
<br>
I'm going to play with this some more.<br>
<br>
Thanks<br>
<font color="#888888">Jay<br>
</font><div><div></div><div class="h5"><br>
On Tue, Aug 3, 2010 at 1:41 PM, Joel Limardo<br>
<<a href="mailto:joel.limardo@forwardphase.com">joel.limardo@forwardphase.com</a>> wrote:<br>
> Perhaps you found a better solution by now but I figured I would respond<br>
> anyway for kicks.<br>
> I reworked my example to use an XMLHttp object to GET some JSON that would<br>
> do the exact same thing except it a) returns the column headers and b) it<br>
> returns the data in a single statement:<br>
> data.addRows(myJSONObj.actualData);<br>
> The JSON looks like this:<br>
> {<br>
> "columns":["Sales","SalesValue"],<br>
> "actualData":[<br>
> ["2001",100],<br>
> ["2002",200],<br>
> ["2003",300],<br>
> ["2004",400],<br>
> ["2005",800]<br>
> ]<br>
> }<br>
> Again, the actual example is<br>
> here: <a href="http://www.bixchange.com/cgi-bin/bixchange/bixchange.cgi?pom=test-gsapi;iid=0001" target="_blank">http://www.bixchange.com/cgi-bin/bixchange/bixchange.cgi?pom=test-gsapi;iid=0001</a><br>
> Some problems I noticed<br>
> -------------------------------------<br>
> My original idea was to use HTML::Template to push out JSON the same way one<br>
> pushes out HTML. This didn't pan out because I wanted to format a JSON array<br>
> with a TMPL_LOOP but it wound up producing an extra comma at the end. That<br>
> was causing a JSON parsing error in IE. Apparently the inability to parse<br>
> an extra comma at the end of the array definition is documented on the<br>
> Google visualization website somewhere and was pretty annoying.<br>
> All in all, the code example is pretty sloppy but works. I borrowed much of<br>
> the browser check code and I think it is rubbish so please don't copy any of<br>
> that for anything important. I also assumed that the first column would<br>
> always be text and the other columns of data would be numeric. I'm certain<br>
> that you could come up with something better. Lastly I used an eval() in<br>
> the code to convert the server's response text to a JavaScript object. There<br>
> is some concern on the web that this may be a vulnerability so I would<br>
> research using better methods.<br>
> On Mon, Aug 2, 2010 at 3:18 PM, Jay Strauss <<a href="mailto:me@heyjay.com">me@heyjay.com</a>> wrote:<br>
>><br>
>> ><br>
>> > I would imagine the JSON example is pretty much the exact same thing<br>
>> > except<br>
>> > you just create a separate template to push out JSON and return this<br>
>> > back to<br>
>> > a static HTML file pointing to its URL. This is pretty elementary<br>
>> > stuff,<br>
>> > however...perhaps I'm missing the problem here...?<br>
>> > --<br>
>> > Sincerely,<br>
>> ><br>
>> >> _______________________________________________<br>
>> > Chicago-talk mailing list<br>
>> > <a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
>> > <a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
>> ><br>
>><br>
>><br>
>> So outside the fact that I'm a pretty elementary fellow, and your way<br>
>> is perfectly fine, and I was starting to think I'd need to do<br>
>> something similar, I thought based on my reading of the docs, that I<br>
>> could be one of the K00L kids.<br>
>><br>
>> I thought I could have my Javascript call the data source directly.<br>
>> And there was some magic in the google javascript classes that would<br>
>> take the CVS file that is returned and stick it in the data source<br>
>> automagically. That way my source web page that is delivered to the<br>
>> browser wouldn't be thousands of lines long of:<br>
>> data.addRows<br>
>> data.addRows<br>
>> data.addRows<br>
>> ...<br>
>><br>
>> Again, its very possible (dare I say probable) I'm total incorrect<br>
>> about how this google visualization stuff works. But it looks like<br>
>> you can do what I'm talking about if the datasource is a google<br>
>> spreadsheet.<br>
>><br>
>> Thanks<br>
>> Jay<br>
>> _______________________________________________<br>
>> Chicago-talk mailing list<br>
>> <a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
>> <a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
><br>
><br>
><br>
><br>
> _______________________________________________<br>
> Chicago-talk mailing list<br>
> <a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
> <a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
><br>
_______________________________________________<br>
Chicago-talk mailing list<br>
<a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
</div></div></blockquote></div><br><br clear="all"><br><br>
</div>