Wednesday, May 13, 2015

Sample C# code to Generate linear Y axis value for a chart from the given amount.

Below is a sample C# code to Generate linear Y axis value for a chart from the given amount. You wil get the lower bound of the y axis value when you call the CalculateLowerBound method. That will be added itself based on the barCount in a loop to get the linear y axis values.
public List GenerateAxis()
{
 int barCount = 5;
 double amount = 10000;
 double money = CalculateLowerBound(amount, barCount);

 var axisVal = new List();

 double valX = 0;
 for (int i = 1; i <= barCount; i++)
 {
  valX += money;
  axisVal.Add(valX);
 }

 return axisVal;
}

public double CalculateLowerBound(double range, int barCount)
{
 double unroundedTickSize = range / (barCount);
 double x = Math.Ceiling(Math.Log10(unroundedTickSize) - 1);
 double pow10x = Math.Pow(10, x);
 return Math.Ceiling(unroundedTickSize / pow10x) * pow10x;
}

No comments:

Post a Comment