Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript - calculate average from multid array

Posted on 2013-05-09
1
Medium Priority
?
342 Views
Last Modified: 2013-05-09
Hi,

How do I calculate the average of y?

var activity = [{
	name: 'activity',
	data: 
		[
		{name: 'one', color: '#2c2d2f', y: 12.00}, 
		{name: 'two', color: '#189e31', y: 78.4},
		{name: 'three', color: '#c1171d', y: 9.6}
		]
}]

Open in new window


Thanks
0
Comment
Question by:mhdi
1 Comment
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 39154061
test page : http://jsfiddle.net/wHbcW/
var activity = [{
	name: 'activity',
	data: 
		[
		{name: 'one', color: '#2c2d2f', y: 12.00}, 
		{name: 'two', color: '#189e31', y: 78.4},
		{name: 'three', color: '#c1171d', y: 9.6}
		]
}];

var total = 0;
var q = activity[0].data.length;
for(var i=0;i<q;i++) total += activity[0].data[i].y;
var avg = total/q;

alert(avg);

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question