Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
_proto_ and JSON
Message
From
18/07/2014 03:32:58
 
 
To
17/07/2014 15:18:12
General information
Forum:
Javascript
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01603953
Message ID:
01604000
Views:
28
>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)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform