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">&lt;<a href="mailto:me@heyjay.com">me@heyjay.com</a>&gt;</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&#39;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&amp;range=B1:D11&amp;pub=1" target="_blank">http://spreadsheets.google.com/tq?key=pCQbetd-CptGXxxQIG7VFIQ&amp;range=B1:D11&amp;pub=1</a><br>
<br>
with the proper header:<br>
google.visualization.Query.setResponse({version:&#39;0.6&#39;,status:&#39;ok&#39;,sig:&#39;1068688546&#39;,table:<br>
bunch &#39;o JSON..<br>
<br>
I can shove it right into the datatable without parsing like:<br>
<br>
var data = response.getDataTable();<br>
<br>
I&#39;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>
&lt;<a href="mailto:joel.limardo@forwardphase.com">joel.limardo@forwardphase.com</a>&gt; wrote:<br>
&gt; Perhaps you found a better solution by now but I figured I would respond<br>
&gt; anyway for kicks.<br>
&gt; I reworked my example to use an XMLHttp object to GET some JSON that would<br>
&gt; do the exact same thing except it a) returns the column headers and b) it<br>
&gt; returns the data in a single statement:<br>
&gt; data.addRows(myJSONObj.actualData);<br>
&gt; The JSON looks like this:<br>
&gt; {<br>
&gt;   &quot;columns&quot;:[&quot;Sales&quot;,&quot;SalesValue&quot;],<br>
&gt;   &quot;actualData&quot;:[<br>
&gt;                  [&quot;2001&quot;,100],<br>
&gt;                  [&quot;2002&quot;,200],<br>
&gt;                  [&quot;2003&quot;,300],<br>
&gt;                  [&quot;2004&quot;,400],<br>
&gt;                  [&quot;2005&quot;,800]<br>
&gt;               ]<br>
&gt; }<br>
&gt; Again, the actual example is<br>
&gt; 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>
&gt; Some problems I noticed<br>
&gt; -------------------------------------<br>
&gt; My original idea was to use HTML::Template to push out JSON the same way one<br>
&gt; pushes out HTML. This didn&#39;t pan out because I wanted to format a JSON array<br>
&gt; with a TMPL_LOOP but it wound up producing an extra comma at the end.  That<br>
&gt; was causing a JSON parsing error in IE.  Apparently the inability to parse<br>
&gt; an extra comma at the end of the array definition is documented on the<br>
&gt; Google visualization website somewhere and was pretty annoying.<br>
&gt; All in all, the code example is pretty sloppy but works.  I borrowed much of<br>
&gt; the browser check code and I think it is rubbish so please don&#39;t copy any of<br>
&gt; that for anything important. I also assumed that the first column would<br>
&gt; always be text and the other columns of data would be numeric. I&#39;m certain<br>
&gt; that you could come up with something better.  Lastly I used an eval() in<br>
&gt; the code to convert the server&#39;s response text to a JavaScript object. There<br>
&gt; is some concern on the web that this may be a vulnerability so I would<br>
&gt; research using better methods.<br>
&gt; On Mon, Aug 2, 2010 at 3:18 PM, Jay Strauss &lt;<a href="mailto:me@heyjay.com">me@heyjay.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I would imagine the JSON example is pretty much the exact same thing<br>
&gt;&gt; &gt; except<br>
&gt;&gt; &gt; you just create a separate template to push out JSON and return this<br>
&gt;&gt; &gt; back to<br>
&gt;&gt; &gt; a static HTML file pointing to its URL.  This is pretty elementary<br>
&gt;&gt; &gt; stuff,<br>
&gt;&gt; &gt; however...perhaps I&#39;m missing the problem here...?<br>
&gt;&gt; &gt; --<br>
&gt;&gt; &gt; Sincerely,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt; &gt; Chicago-talk mailing list<br>
&gt;&gt; &gt; <a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
&gt;&gt; &gt; <a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
&gt;&gt; &gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; So outside the fact that I&#39;m a pretty elementary fellow, and your way<br>
&gt;&gt; is perfectly fine, and I was starting to think I&#39;d need to do<br>
&gt;&gt; something similar, I thought based on my reading of the docs, that I<br>
&gt;&gt; could be one of the K00L kids.<br>
&gt;&gt;<br>
&gt;&gt; I thought I could have my Javascript call the data source directly.<br>
&gt;&gt; And there was some magic in the google javascript classes that would<br>
&gt;&gt; take the CVS file that is returned and stick it in the data source<br>
&gt;&gt; automagically.  That way my source web page that is delivered to the<br>
&gt;&gt; browser wouldn&#39;t be thousands of lines long of:<br>
&gt;&gt; data.addRows<br>
&gt;&gt; data.addRows<br>
&gt;&gt; data.addRows<br>
&gt;&gt; ...<br>
&gt;&gt;<br>
&gt;&gt; Again, its very possible (dare I say probable) I&#39;m total incorrect<br>
&gt;&gt; about how this google visualization stuff works.  But it looks like<br>
&gt;&gt; you can do what I&#39;m talking about if the datasource is a google<br>
&gt;&gt; spreadsheet.<br>
&gt;&gt;<br>
&gt;&gt; Thanks<br>
&gt;&gt; Jay<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Chicago-talk mailing list<br>
&gt;&gt; <a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
&gt;&gt; <a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Chicago-talk mailing list<br>
&gt; <a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
&gt; <a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
&gt;<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>