DataPointComparer.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using FastReport.DataVisualization.Charting;
  5. namespace FastReport.MSChart
  6. {
  7. internal class DataPointComparer : IComparer<DataPoint>
  8. {
  9. private SortBy sortBy;
  10. private ChartSortOrder sortOrder;
  11. public int Compare(DataPoint x, DataPoint y)
  12. {
  13. int result = 0;
  14. IComparable i1;
  15. IComparable i2;
  16. if (sortBy == SortBy.XValue)
  17. {
  18. if (!String.IsNullOrEmpty(x.AxisLabel))
  19. {
  20. i1 = x.AxisLabel as IComparable;
  21. i2 = y.AxisLabel as IComparable;
  22. }
  23. else
  24. {
  25. i1 = x.XValue as IComparable;
  26. i2 = y.XValue as IComparable;
  27. }
  28. }
  29. else
  30. {
  31. i1 = x.YValues[0] as IComparable;
  32. i2 = y.YValues[0] as IComparable;
  33. }
  34. if (i1 != null)
  35. result = i1.CompareTo(i2);
  36. else if (i2 != null)
  37. result = -1;
  38. if (sortOrder == ChartSortOrder.Descending)
  39. result = -result;
  40. return result;
  41. }
  42. public DataPointComparer(SortBy sortBy, ChartSortOrder sortOrder)
  43. {
  44. this.sortBy = sortBy;
  45. this.sortOrder = sortOrder;
  46. }
  47. }
  48. }