public static void DrawLines(ref Bitmap Bmp, int[] yValues, Color LineColor, string ValueStructure = "{0}", int Padding = 20, int Thickness = 2, string[] Labels = null, string xLabel = null, string yLabel = null, int FontSize = 1) { if ((xLabel != null || yLabel != null) && Padding < 20) { Padding = 20; } //If we have axis labels, ensure we have enough space for them float xStep = (float)(Bmp.Width - (Padding * 2)) / (yValues.Length - 1), yStep = (float)(Bmp.Height - (Padding * 2)) / (Linq.Max(yValues, x => x)[0] - Linq.Min(yValues, x => x)[0]), yOffset = yStep * Linq.Min(yValues, x => x)[0]; //Calculate how many pixels per unit on the x,y axes and how far to shift the grid down by string T1 = null, T2 = null; int Align = 1; //Indicates direction of text write //Draw the lines for the x and y axes BitMapHandling.DrawLine(ref Bmp, BitMapHandling.PointRelativeToOrigin(Bmp, Padding / 2, Padding / 2), BitMapHandling.PointRelativeToOrigin(Bmp, Bmp.Width - (Padding / 2), Padding / 2), Color.Gray, 3); BitMapHandling.DrawLine(ref Bmp, BitMapHandling.PointRelativeToOrigin(Bmp, Padding / 2, Padding / 2), BitMapHandling.PointRelativeToOrigin(Bmp, Padding / 2, Bmp.Height - Padding), Color.Gray, 3); if (xLabel != null)//Write the x axes label at intervals below the line { for (int x = 1; x < yValues.Length - 1; x += 5) { BitMapHandling.DrawText(ref Bmp, BitMapHandling.PointRelativeToOrigin(Bmp, xStep * x + Padding, Padding / 2 - 5), xLabel, Color.Black, 2, 0); } } if (yLabel != null)//Write the y axes label above the y axes line { BitMapHandling.DrawText(ref Bmp, BitMapHandling.PointRelativeToOrigin(Bmp, Padding / 2, Bmp.Height - (Padding / 2)), yLabel, Color.Black, 2, 1); } if (Labels != null && Labels.Length != yValues.Length) { throw new Exception("Labels and yValues length missmatch"); } //Throw an error if we dont have enough labels for the values for (int i = 0; i < yValues.Length - 1; i++) //For every point { Point P1 = BitMapHandling.PointRelativeToOrigin(Bmp, i * xStep + Padding, (yValues[i] * yStep) + Padding - yOffset), P2 = BitMapHandling.PointRelativeToOrigin(Bmp, (i + 1) * xStep + Padding, (yValues[i + 1] * yStep) + Padding - yOffset);//Caclulate the Points for itself and the next point if (i != 0) { Align = 0; } //Change the text align to center if (Labels != null) //Set the names of the points { T1 = Labels[i]; if (i == yValues.Length - 2) { T2 = Labels[i + 1]; } } DrawDataPoint(ref Bmp, P1, yValues[i], P2, yValues[i + 1], T1, T2, ValueStructure, LineColor, Thickness, Padding, FontSize, Align);//Draw the points and their details } }
private static void Main(string[] args) { Random Rnd = new Random(); int[] A = new int[100]; for (int i = 0; i < A.Length; i++) { A[i] = Rnd.Next(1, 5000); } int Count = Linq.Count(A, x => x < 6); int[] Where = Linq.Where(A, x => x < 6); int[] Max = Linq.Max(A, x => x); Linq.Sort(A, x => x); Linq.Reverse(A); }