Sign in to follow this  
raxdex

How to calculate sum of all values of Y axis for column3D chart.

Recommended Posts

e.g <graph xAxisName='Month' yAxisName='No. of Items' decimalPrecision='0' formatNumberScale='0'><set name='Jan' value='45' color='AFD8F8' /><set name='Feb' value='49' color='F6BD0F' /><set name='Mar' value='42' color='8BBA00' /><set name='Apr' value='25' color='FF8E46' /><set name='May' value='43' color='008E8E' /><set name='Jun' value='22' color='D64646' /><set name='Jul' value='48' color='8E468E' /><set name='Aug' value='46' color='588526' /><set name='Sep' value='24' color='B3AA00' /><set name='Oct' value='45' color='008ED6' /><set name='Nov' value='42' color='9D080D' /><set name='Dec' value='32' color='A186BE' /></graph>

here i want o/p as : (45+49+42+25+43+22+48+46+24+45+42+32) = 463 in javascript variable

e.g var val ;

Share this post


Link to post
Share on other sites
Guest Madhumita

Hello,

Welcome to FusionCharts Forum. :)

Our charts  do not support aggregate functions.

However, you can write your own javascript function to achieve this.

You can follow the steps below to achieve this:

1. getXML

2. build a javascript function say getSum()

3. Parse through the XML and retrieve the value in the value attribute

4.While retrieving the values keep adding them to a variable say sum

5.return the sum to the browser

Hope this helps. :D

Share this post


Link to post
Share on other sites

Hi, Madhumita

Thanks for u r urgent reply. I am new in this area so please help me out.

You said regarding getXML method to retrive data from graph.

can u plz give me getSum() function code specifically getXML method for column2D graph.

Share this post


Link to post
Share on other sites
Guest Madhumita

Hello,

Here is a piece of code to help you:

<script type="text/javascript">

  FusionChartsGetValues = function(sourceXML) {

  if(typeof sourceXML != 'string') {

  throw "ArgumentException() :: sourceXML is nopt string.";

  }

  var r = [];

  var a = sourceXML.replace(/<set.+?value="(.+?)"|<set.+?value='(.+?)'/ig,

  function($1, $2, $3) {

  r.push(parseInt($2 || $3));

  });

  return r;

  };

  function getSum(fromXML) {

  var a = FusionChartsGetValues(fromXML), s=0;

  while(a.length) { s+= a.pop(); }

  return s;

  }

  alert(getSum("<graph xAxisName='Month' yAxisName='No. of Items' decimalPrecision='0' formatNumberScale='0'><set name='Jan' value='45' color='AFD8F8' /><set name='Feb' value='49' color='F6BD0F' /><set name='Mar' value='42' color='8BBA00' /><set name='Apr' value='25' color='FF8E46' /><set name='May' value='43' color='008E8E' /><set name='Jun' value='22' color='D64646' /><set name='Jul' value='48' color='8E468E' /><set name='Aug' value='46' color='588526' /><set name='Sep' value='24' color='B3AA00' /><set name='Oct' value='45' color='008ED6' /><set name='Nov' value='42' color='9D080D' /><set name='Dec' value='32' color='A186BE' /></graph>"));

  </script>

Here in the getSum() , use getXML function to get the XML from the chart.

Hope this helps. :)

Share this post


Link to post
Share on other sites
Hi Madhumita,

Again Thanks for u r urgent reply.

It really helped me. It was not possible without your help !

Once again Thank you so much.....

Regards,

RxDx

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this