/// <summary> /// Called to paint the control. /// </summary> protected override void OnPaint(PaintEventArgs e) { int xPos = 0; int visibleValues = (Width - xPos) / SPACING; int firstValueIdx = values.Count - visibleValues; if (firstValueIdx < 0) { firstValueIdx = 0; } double minValue = 0.0; double maxValue = 0.0; double total = 0.0; // clear all stats. statistics.Clear(); for (int valIdx = firstValueIdx; valIdx < values.Count; ++valIdx) { Measurement msr = values[valIdx]; double val = msr.Value; if (valIdx != firstValueIdx) { if (val < minValue) { minValue = val; } if (val > maxValue) { maxValue = val; } } else { maxValue = val + 1.0; minValue = val - 1.0; } // add statistics value for this group if it's not there yet. if (!statistics.ContainsKey(msr.Color)) { statistics[msr.Color] = new Statistics(msr.Color, val); } else { statistics[msr.Color].AddValue(val); } total += val; } int avg = (int)Math.Round(total / values.Count); for (int valIdx = firstValueIdx; valIdx < values.Count; ++valIdx) { Measurement msr = values[valIdx]; double val = msr.Value; double ratio = (val - minValue) / (maxValue - minValue); int yPos = (int)Math.Round(ratio * (double)Height); e.Graphics.DrawLine( new Pen(msr.Color), new Point(xPos, Height - yPos), new Point(xPos, Height)); xPos += SPACING; } }
/// <summary> /// Adds a Measurement object. /// </summary> public void AddValue(Measurement measurement) { values.Add(measurement); Invalidate(); }