Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
_proto_ and JSON
Message
De
18/07/2014 16:55:02
 
 
À
18/07/2014 10:41:30
Information générale
Forum:
Javascript
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01603953
Message ID:
01604129
Vues:
30
>>>Again, calling an SP that should be returning an array of data points, ie
>>>
>>>[["DB1", 2],["DB2,4],...["COM",10]]
>>>
>>>via an Ajax call, fed into a variable "DataArray" which is then fed into GoogleCharts.
>>>
>>>Here's the code:
>>>
>>>        google.load("visualization", "1", { packages: ["corechart"] });
>>>        google.setOnLoadCallback(drawChart);
>>>
>>>        function drawChart() {
>>>            var AjaxData = $.ajax({
>>>                type: "POST",
>>>                contentType: "application/json;",
>>>                url: "WebForm1.aspx/GetHeartBeatData",
>>>                 dataType: "json",
>>>                async: false
>>>              }).responseText;
>>>     
>>>            var MyArray = JSON.parse(AjaxData);
>>>            var DataArray = JSON.parse(MyArray.d);
>>>            var data = google.visualization.arrayToDataTable(DataArray);
>>>
>>>
>>>Here's what I get:
>>>
>>>		AjaxData	"{"d":"[{\"time\":1,\"db1\":1,\"db2\":2,\"db3\":3,\"db4\":4,\"db5\":5,\"db6\":6,\"db7\":7,\"db8\":8,\"comm\":9},{\"time\":2,\"db1\":4,\"db2\":5,\"db3\":6,\"db4\":7,\"db5\":8,\"db6\":6,\"db7\":4,\"db8\":2,\"comm\":1},{\"time\":3,\"db1\":9,\"db2\":8,\"db3\":7,\"db4\":3,\"db5\":2,\"db6\":1,\"db7\":1,\"db8\":2,\"comm\":3}]"}"	String
>>>
>>>-		MyArray	{...}	Object
>>>+		__proto__	{...}	Object
>>>		d	"[{"time":1,"db1":1,"db2":2,"db3":3,"db4":4,"db5":5,"db6":6,"db7":7,"db8":8,"comm":9},{"time":2,"db1":4,"db2":5,"db3":6,"db4":7,"db5":8,"db6":6,"db7":4,"db8":2,"comm":1},{"time":3,"db1":9,"db2":8,"db3":7,"db4":3,"db5":2,"db6":1,"db7":1,"db8":2,"comm":3}]"	String
>>>
>>>-		[0]	{...}	Object
>>>+		__proto__	{...}	Object
>>>		comm	9	Number
>>>		db1	1	Number
>>>		db2	2	Number
>>>		db3	3	Number
>>>		db4	4	Number
>>>		db5	5	Number
>>>		db6	6	Number
>>>		db7	7	Number
>>>		db8	8	Number
>>>		time	1	Number
>>>
>>>
>>>I pass DataArray to GoogleCharts and I get either "Not an array" or Invalid row type for row 0. Apparently, the '_proto_' is the issue. Please don't tell me that what I'm doing should work. It doesn't.
>>>
>>>
>>>
>>>I'm REALLY getting tired of beating my head against this brick wall.
>>
>>The array you're getting back from 'GetHeartBeatData' looks as if it is in the wrong format - it's an array of objects rather than an array of data. To get data that can converted to the format expected by Google.visualization it should be something like:
"{\"d\":[ [\"Time\",\"db1\",\"db2\",\"db3\",\"db4\"],[\"1:00\",54,50,57,47],[\"2:00\",56,46,63,20]]}";
(assuming you want to pass header information in the first row)
>>
>>
>>Also, if you parse 'AjaxData' then the contained 'myArray:' would also be parsed. Just use myArray.d rather then JSON.Parse(myArray.d)
>
>using just MyArray.d returns "Not an Array" from Google Charts
>
>Obviously I'm missing something that's probably very simple - all I need to do is call an SP that returns an array and get Google Charts to accept it, and do this on the client side.

As before - Google returns 'Not an array' because it's getting an array of objects when it is expecting a simple array (with or without header information in the first row depending on the second parameter).
You either need to adjust the data returned from the server or spin through the objects and create the simple array as required by google.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform