|
-
Oct 18th, 2012, 10:31 PM
#1
Thread Starter
Hyperactive Member
associative array in JS
hi all,
i have written an API in html5. and this is how i load it
HTML Code:
$(document).ready(function(){
oChart= new _chart("canvas4");
oChart.props.values= = [{ Name: "Rob", max:33, actual : 10, actual2: 15, color: "red" },
{ Name: "Carole", max: 28, actual : 9, actual2: 17,color: "greenyellow" },
{ Name: "David", max: 36, actual : 16, actual2: 8,color: "cyan" }
];;
oChart.refresh();
});
the dilema is, figures in the values array should be updated every second, and i can do that by calling ajax method that returns a tring in the format
[color][{ Name: "Rob", max:33, actual : 10, actual2: 15, color: "red" },
{ Name: "Carole", max: 28, actual : 9, actual2: 17,color: "greenyellow" },
{ Name: "David", max: 36, actual : 16, actual2: 8,color: "cyan" }
];[/color]
how to evaluate the returned string into the values array ??
thanks in advance ..
-
Oct 19th, 2012, 01:50 AM
#2
Re: associative array in JS
If you were to put quotes around the keys, it would become valid JSON, and then you could use JSON.parse to evaluate the string.
Otherwise, you're limited to eval, which is not the best option because it parses and executes more than just data structures.
-
Nov 14th, 2012, 12:02 AM
#3
Thread Starter
Hyperactive Member
Re: associative array in JS
Thanks, eval() worked for me.. any ideas how to display data based on mouse position over the canvas
here is an example: http://www.koolchart.com/demo/
check out Barchart
-
Jan 22nd, 2013, 08:04 AM
#4
Registered User
Re: associative array in JS
In JS objects are also associative arrays or hashes.
theStatus.Home
can also be read.
theStatus['Home']
You can access a form by performing these DOM calls:
document.forms['theForm']
document.forms.theForm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|