Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Javascript - calculate average from multid array

Posted on 2013-05-09
1
Medium Priority
?
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 82

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

722 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