public int IndexOf(ChartColumn column) { return(this.List.IndexOf(column)); }
public bool Contains(ChartColumn column) { return(this.List.Contains(column)); }
public void Remove(ChartColumn column) { this.List.Remove(column); }
public void Insert(int index, ChartColumn column) { this.List.Insert(index, column); }
public int Add(ChartColumn column) { return(this.List.Add(column)); }
protected void PlotData() { // TODO: Support for more than one axis! if (_IndependentColumns.Count == 0) { throw new Exception("Graph requires at least one independant column"); } GraphicsState gs = _Graphics.Save(); _Graphics.TranslateTransform(_Margins.Left, _Margins.Top); ChartColumn columnX = _IndependentColumns[0]; Range rangeX = columnX.Range; // Sort the data by independent column DataView dataView = new DataView(_Data); dataView.Sort = string.Format("[{0}] ASC", columnX.ColumnName); DataTable data = dataView.ToTable(); int colNum = 0; foreach (ChartColumn columnY in _DependentColumns) { Range rangeY = columnY.Range; List <PointF> points = new List <PointF>(512); float lastX = 0, lastY = 0; bool firstPoint = true; foreach (DataRow row in data.Rows) { if (row[columnY.ColumnName].GetType() == typeof(DBNull)) { continue; } float x = 0, y = 0; float yVal = rangeY.Normalize(row[columnY.ColumnName]); float xVal = rangeX.Normalize(row[columnX.ColumnName]); y = _Margins.Height - yVal * _Margins.Height; x = xVal * _Margins.Width; if (firstPoint) { points.Add(new PointF(x, _Margins.Height)); } firstPoint = false; points.Add(new PointF(x, y)); lastX = x; lastY = y; } points.Add(new PointF(lastX, _Margins.Height)); Color color = ColorTranslator.FromHtml(columnY.LineColor); Brush plotBrush = new SolidBrush(color); Pen plotPen = new Pen(color, _PlotWidth); GraphicsPath path = new GraphicsPath(); switch (_Type) { case ChartType.Line: { // Line graph points.RemoveAt(0); points.RemoveAt(points.Count - 1); path.AddLines(points.ToArray()); _Graphics.DrawPath(plotPen, path); } break; case ChartType.Area: { // Area graph path.AddLines(points.ToArray()); _Graphics.FillPath(plotBrush, path); } break; case ChartType.Scatter: { // Scatter plot // Skip first and last "anchor" points for (int i = 1; i < points.Count - 1; i++) { path.AddRectangle(new RectangleF( points[i].X - 2.0f, points[i].Y - 2.0f, 4.0f, 4.0f)); } _Graphics.DrawPath(plotPen, path); } break; case ChartType.Bar: { // Scatter plot // Skip first and last "anchor" points float leftOffset = (_DependentColumns.Count * _BarWidth) / 2; float offset = leftOffset + colNum * _BarWidth; for (int i = 1; i < points.Count - 1; i++) { path.AddRectangle(new RectangleF( points[i].X - offset, points[i].Y, _BarWidth, _Margins.Height - points[i].Y)); } _Graphics.FillPath(plotBrush, path); } break; } colNum++; } _Graphics.Restore(gs); }
protected void DrawGrid() { _Graphics.DrawRectangle(_ForegroundPen, _Margins); #region Vertical Grid if (_DrawVerticalGrid || _DrawScale) { int rangeCnt = 0; foreach (Range range in _Ranges) { rangeCnt++; for (int step = 0; step < range.Steps; step++) { float y = range.GetStepFloat(step); float scaledY = (y / range.FloatDiff) * _Margins.Height; if (_DrawVerticalGrid && rangeCnt == 1) { _Graphics.DrawLine(_DarkGridPen, new PointF(_Margins.Left, (float)(_Margins.Bottom - scaledY)), new PointF(_Margins.Right, (float)(_Margins.Bottom - scaledY))); } if (_DrawScale) { float textBoxTop = (float)(_Margins.Bottom - scaledY - _ScaleFont.Height); float textBoxLeft = 0; StringFormat labelFmtY = new StringFormat(); labelFmtY.LineAlignment = StringAlignment.Center; bool drawThisScale = true; if (rangeCnt == 1) // #1 - left side { labelFmtY.Alignment = StringAlignment.Far; textBoxLeft = 0; } else if (rangeCnt == 2) { labelFmtY.Alignment = StringAlignment.Near; textBoxLeft = _Margins.Right; } else { // Experimental labelFmtY.Alignment = StringAlignment.Near; textBoxLeft = _Margins.Right + _ScaleWidth * (rangeCnt - 2); } /** * else // I can only draw two scales, one on either side * drawThisScale = false; **/ if (drawThisScale) { object mark = range.GetStep(step); string label = ""; if (mark.GetType() == typeof(DateTime)) { label = ((DateTime)mark).ToString("d"); } else if (mark.GetType() == typeof(float)) { label = ((float)mark).ToString("#,###,###,##0.#####"); } _Graphics.DrawString(label, _ScaleFont, _ScaleTextBrush, new RectangleF(textBoxLeft, textBoxTop, _Margins.Left, _ScaleFont.Height * 2), labelFmtY); } } } } } #endregion #region Horizontal Grid if (_DrawHorizontalGrid || _DrawScale) { // TODO: Support for more than one axis! if (_IndependentColumns.Count == 0) { throw new Exception("Graph requires at least one independant column"); } ChartColumn column = _IndependentColumns[0]; Range range = column.Range; for (int step = 0; step < range.Steps; step++) { float x = range.GetStepFloat(step); float scaledX = (x / range.FloatDiff) * _Margins.Width; if (_DrawHorizontalGrid) { _Graphics.DrawLine(_DarkGridPen, new PointF((float)(_Margins.Right - scaledX), _Margins.Top), new PointF((float)(_Margins.Right - scaledX), _Margins.Bottom)); } if (_DrawScale) { float textBoxLeft = (float)(_Margins.Right - scaledX); StringFormat labelFmtX = new StringFormat(); labelFmtX.LineAlignment = StringAlignment.Center; labelFmtX.Alignment = StringAlignment.Far; bool diagonal = true; object mark = range.GetStep(step); string label = ""; if (range.GetType() == typeof(TimeRange)) { if (((TimeRange)range).Interval.Interval == DateInterval.Hourly) { label = ((DateTime)mark).ToString("g"); } else { label = ((DateTime)mark).ToString("d"); } } else if (range.GetType() == typeof(NumberRange)) { label = ((float)mark).ToString("#,###,###,##0.#####"); } // Save state GraphicsState gs = _Graphics.Save(); // Translate and Rotate _Graphics.ResetTransform(); _Graphics.TranslateTransform(textBoxLeft, _Margins.Bottom + 5); if (diagonal) { _Graphics.RotateTransform(-45); } _Graphics.DrawString(label, _ScaleFont, _ScaleTextBrush, new Point(0, 0 /*, _Margins.Left, _ScaleFont.Height * 2*/), labelFmtX); _Graphics.Restore(gs); } } } #endregion }