1. C# / Говнокод #6578

    +119

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    public static Bitmap DrawBarsChart(ChartType t, Size s)
        {
          double[] values = DataValues;
          string[] names = DataNames;
          Bitmap bmp = new Bitmap(s.Width, s.Height);
          if (t != ChartType.bars || names.Length != values.Length || names.Length < 2)
            return bmp;
          else
          {
            Graphics g = Graphics.FromImage(bmp as Image);
            g.Clear(Color.White);
            g.DrawLines(new Pen(Brushes.Black), new Point[] { new Point(20, 20), new Point(20, s.Height - 20), new Point(s.Width - 200, s.Height - 20) });
            int Columnwidth = (s.Width - 240) / values.Length;
            if (Columnwidth > 150) Columnwidth = 150;
            double maxvalue = values.Max();
            int counter = 1;
            int rangefirst;
            int rangesecond;
     
            while (true)
            {
              if (maxvalue / Math.Pow(10, counter) < 10)
              {
                rangefirst = (int)Math.Floor(maxvalue / Math.Pow(10, counter));
                rangesecond = (int)(maxvalue - rangefirst * Math.Pow(10, counter));
                break;
              }
              else
              {
                counter++;
              }
            }
            int rangepix = (s.Height - 60) / (rangefirst + 1);
            for (int i = 0; i < rangefirst + 1; i++)
            {
              g.DrawString((i * Math.Pow(10, counter)).ToString(), new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular),
                Brushes.Black, new PointF(0, s.Height - 30 - rangepix * i));
              g.DrawLine(new Pen(Brushes.Black), new Point(17, s.Height - 20 - rangepix * i), new Point(20, s.Height - 20 - rangepix * i));
            }
            Colors colors = new Colors(); //класс-контейнер цветов (99 штук)
            int startcolor = new Random(DateTime.Now.Millisecond).Next(99);
            int j = startcolor;
            int startx = 21;
            int ColumnNumber = 1;
            foreach (var value in values)
            {
              int curfirstrange = (int)Math.Floor(value / Math.Pow(10, counter));
              int cursecondrange = (int)(value - curfirstrange * Math.Pow(10, counter));
              int rangesmallpix = (int)(cursecondrange * rangepix / Math.Pow(10, counter));
              g.FillRectangle(new SolidBrush(colors.GetNextColor(j)), startx,
                s.Height - 20 - curfirstrange * rangepix - rangesmallpix, Columnwidth, curfirstrange * rangepix + rangesmallpix);
              g.DrawString(value.ToString(), new Font(FontFamily.GenericSerif, 10, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(startx + Columnwidth / 2 - 10,
                s.Height - 20 - curfirstrange * rangepix - rangesmallpix - 20));
              g.DrawString(ColumnNumber.ToString(), new Font(FontFamily.GenericSerif, 10, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(startx + Columnwidth / 2 - 10,
                s.Height - 10));
              ColumnNumber++;
              j++; if (j > 99) j = 0;
              startx += Columnwidth;
            }
            j = startcolor;
            int TopMargin = 20;
            foreach (string str in names)
            {
              string tmp = str;
              if (str.Length > 15)
                tmp = str.Substring(0, 15);
              g.FillRectangle(new SolidBrush(colors.GetNextColor(j)), s.Width - 200, TopMargin, 10, 10); //pucyeM LIBeTHbIe kBagpaTuku
              g.DrawString(tmp, new Font(FontFamily.GenericSerif, 12, FontStyle.Italic), Brushes.Black, new PointF(s.Width - 180, TopMargin - 6)); //pucyeM Hagnucu
              TopMargin += 20;
              j++; if (j > 99) j = 0;
            }
            return bmp;
          }
        }

    Запостил: qbasic, 06 Мая 2011

    Комментарии (17) RSS

    Добавить комментарий