Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Ajax, JSON and googlecharts..oh MY!
Message
De
09/07/2014 13:00:15
 
 
À
09/07/2014 10:41:51
Information générale
Forum:
Javascript
Catégorie:
JQuery
Divers
Thread ID:
01603355
Message ID:
01603414
Vues:
39
>>>Has anyone messed with GoogleCharts and Ajax?
>>>
>>
>>What's the eval() doing there ? Since you're converting the response to a string then JSON.Parse(AjaxData) would seem to make more sense ?
>>
>>Also you are specifying a dataType : string which I didn't think exists - I certainly don't see it in the documentation. A valid dataType will override the contentType: application/json - don't know whether 'string' would.
>>
>>What comes over the wire from the server ? Why not drop the dataType and just get the json response which will automatically be parsed.
>
>Dropped the dataType and eval and added a JSON.parse call
>
>The data returning from the server is a string in the form I'm expecting to see when I check it after the Stored Proc call.
>
>["colhead", "colhead2", etc],["hh:mm", n,n,n],["hh:mm",n,n], etc
>
>AjaxData, however, shows up as "{"d":"[\"Time\",\"DB1\",\"DB2\",\"DB3\",\"DB4\"],[\"1:00\",54,50,57,47],[\"2:00\",56,46,63,20],etc,"}" String
>
>JSON.parse(AjaxData) creates MyArray with a MyArray._proto_ and MyArray.d (where the data resides). I need that to be an array MyArray[0].
>
>What am I not doing?

Hmm. The AjaxData string looks odd. 'd' should be an array of arrays so would look like this (note the extra square brackets):
"{\"d\":[ [\"Time\",\"DB1\",\"DB2\",\"DB3\",\"DB4\"],[\"1:00\",54,50,57,47],[\"2:00\",56,46,63,20]]}"
var MyArray = Json.parse(AjaxData) on that would give you an object 'd' with three 'rows' - the first containing the column information and the other two holding data. So if you wanted to pass the whole thing to google visualization it would be:
google.Visualization.arrayToDataTable(MyArray.d,false);
(false indicates first row is header data). If you just wanted the first data row passed in then
google.Visualization.arrayToDataTable(MyArray.d[1]);

Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform