// Draw a histogram. private void DrawHistogram(Graphics gr, Color back_color, double[] values, int width, int height) { //Color[] Colors = new Color[] { Color.Red, Color.LightGreen, Color.Blue, Color.Pink, Color.Green, Color.LightBlue, Color.Orange, Color.Yellow, Color.Purple }; Color[] Colors = new Color[] { Color.FromArgb(5, 11, 230) }; gr.Clear(back_color); // Make a transformation to the PictureBox. DataAnalysis da = new DataAnalysis(); RectangleF data_bounds = new RectangleF(0, 0, values.Length, (float)da.getMaxValue(values)); PointF[] points = { new PointF(0, height), new PointF(width, height), new PointF(0, 0) }; Matrix transformation = new Matrix(data_bounds, points); gr.Transform = transformation; // Draw the histogram. using (Pen thin_pen = new Pen(Color.White, 0)) { for (int i = 0; i < values.Length; i++) { RectangleF rect = new RectangleF(i, 0, 1, (float)values[i]); using (Brush the_brush = new SolidBrush(Colors[i % Colors.Length])) { gr.FillRectangle(the_brush, rect); gr.DrawRectangle(thin_pen, rect.X, rect.Y, rect.Width, rect.Height); } } } gr.ResetTransform(); gr.DrawRectangle(Pens.Black, 0, 0, width - 1, height - 1); }
private void button1_Click(object sender, EventArgs e) { #region Making sure user's entry is in correct format if (textBox1.Text != null && !String.IsNullOrEmpty(textBox1.Text) && !String.IsNullOrWhiteSpace(textBox1.Text) && Regex.IsMatch(textBox1.Text, @"^[-0-9,\s]+$")) { #region Preparing user's entry for analysis string entry = textBox1.Text.Trim().ToString(); string[] arr = entry.Split(','); double[] doubles = new double[arr.Length]; for (int i = 0; i < arr.Length; i++) { doubles[i] = Convert.ToDouble(arr[i].Trim()); } Array.Sort(doubles); DataAnalysis da = new DataAnalysis(); #endregion #region Measure Of Center meanTxtBox.Text = Math.Round(da.findMean(doubles), 3).ToString(); if (da.findMedian(doubles) != -100.0) { MedianTxtBox.Text = da.findMedian(doubles).ToString(); } else { MedianTxtBox.Text = "Error"; } if (da.findModes(doubles) != null) { StringBuilder stringBuilder = new StringBuilder(); double[] modes = da.findModes(doubles); for (int i = 0; i < modes.Length; i++) { stringBuilder.Append(modes[i].ToString()); stringBuilder.Append(','); } ModeTxtBox.Text = stringBuilder.ToString().Substring(0, stringBuilder.Length - 1); } else { ModeTxtBox.Text = "No modes for this array"; } #endregion #region Measure Of Spread standardDeviationTxtBox.Text = Math.Round(da.findStdDeviation(doubles), 3).ToString(); VarianceTxtBox.Text = Math.Round(da.findVariance(doubles), 3).ToString(); #region Five Number Summary MaxTxtBox.Text = da.getMaxValue(doubles).ToString(); MinTxtBox.Text = da.getMinValue(doubles).ToString(); RangeTxtBox.Text = da.range(doubles).ToString(); double[] fiveNumberSummary = da.findIQR(doubles); q1TxtBox.Text = fiveNumberSummary[0].ToString(); q2TxtBox.Text = fiveNumberSummary[2].ToString(); iqrTxtBox.Text = fiveNumberSummary[3].ToString(); #endregion #endregion } else { Notification toast = new Notification("Data Analysis Tool", "Your entry is not in the correct format", 2, FormAnimator.AnimationMethod.Center, FormAnimator.AnimationDirection.Down); toast.Show(); } #endregion }