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.
  1. public List GenerateAxis()
  2. {
  3. int barCount = 5;
  4. double amount = 10000;
  5. double money = CalculateLowerBound(amount, barCount);
  6. var axisVal = new List();
  7. double valX = 0;
  8. for (int i = 1; i <= barCount; i++)
  9. {
  10. valX += money;
  11. axisVal.Add(valX);
  12. }
  13. return axisVal;
  14. }
  15. public double CalculateLowerBound(double range, int barCount)
  16. {
  17. double unroundedTickSize = range / (barCount);
  18. double x = Math.Ceiling(Math.Log10(unroundedTickSize) - 1);
  19. double pow10x = Math.Pow(10, x);
  20. return Math.Ceiling(unroundedTickSize / pow10x) * pow10x;
  21. }

No comments:

Post a Comment