Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Location
    Cheshire, UK
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    First Plugin Help

    Hey,

    Im trying to make a graph plugin for jquery to work along side css. I started off by adding all the values in the graph together to get a total value.

    Heres the code for that,

    Code:
    	
                    $.fn.AllVal = function() {
    		   var Max = 0;
    		   this.each(function() {
    		      Max += parseInt($(this).text());
    		   });
    		   return Max;
    		}; //Function AllVal (Add all values together)
    This works fine, and then work out the % of each bit of data by the following math. (run inside a loop ofc)

    Code:
    var value = ((obj.text() / Max * 1)* (100));
    All that worked great.

    You can see the result of the code above working here.

    But most graphs dont work in the way I have done this, and rather than the graph working with the total % some work from the % of the highest number...so Im now looking for a solution to finding how to work out the maximum number from any amount of numbers.

    An example of that would be, if I had the numbers 9300, 2004, 5000, 2000 in the graph I would be able to find out the highest value and assign it to a variable. I have found the math.max() method with javascript but because Im only able to use jQuery just yet, when it comes to adding javascript to jQuery I dont have much clue as to where to start. I've tried googling after quite a few hours im still getting no where. The only thing I can find is ways of working out the same problem I have, but with Flash.

    Heres the full jQuery code so far, Please if theres any problems or improvements or issues with my code im happy for you to tell me, This is only my first and im happy to learn from my mistake.

    http://www.pastebin.com/m1acf1647 (jQuery)

    Thanks for any help your able to give.
    Last edited by Palgie; 02-21-2010 at 08:52 AM. Reason: Explaining the problem better.

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Hi - I'm not sure if I really understand, but...

    ...so you've got this, which returns the sum of all values:

    Code:
    	$.fn.AllVal = function() {
    		var Max = 0;
    		this.each(function() {
    			Max += parseInt($(this).text());
    		});
    		return Max;
    	}; //Function AllVal (Add all values together)
    ... and you want to do a similar function that returns the highest one of those values? Is that right?

    If so, I think this should do it:

    Code:
    	$.fn.HighVal = function() {
    		var Highest = 0;
    		this.each(function() {
    			var thisVal = parseInt($(this).text());
    			if (thisVal > Highest){
    				Highest = thisVal;
    			}
    		});
    		return Highest;
    	};

  • Users who have thanked Spudhead for this post:

    Palgie (02-22-2010)

  • #3
    New to the CF scene
    Join Date
    Feb 2010
    Location
    Cheshire, UK
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts


    That did it!!

    I think I was overcomplicating it massively, the problem was so easily fixed!

    Cant thank you enough for your help, iv been trying to fix this for so long


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •