/* 绘制游标 */ protected virtual void _DrawCursors(Graphics g, Point pt) { for (int ijk = 0; ijk < _Curves.Count; ++ijk) { ChartCurve1V cc = _Curves[ijk]; Dictionary <int, ChartCursor1V> cc_cursors = cc._ChartCursors1V; ChartCursor1V cursor = _GetNearestPtCursor(pt.X, cc_cursors); if (cursor != null) { g.FillEllipse(_OutlinePtBrush, cursor.Pt_x - _CURSOR_HALF_SIDE, cursor.Pt_y - _CURSOR_HALF_SIDE, _CURSOR_HALF_SIDE << 1, _CURSOR_HALF_SIDE << 1); string info = ""; if (CursorFormat == null) { StringBuilder sb = new StringBuilder(); sb.Append("X:").Append(XAxisValueFormat.Format(cursor.YIndex * cc.Delta)); if (!string.IsNullOrEmpty(XAxisUnitName)) { sb.Append("(").Append(XAxisUnitName).Append(")"); } sb.Append("Y:").Append(cc.YAxisValueFormat.Format(cursor.Y_max)); if (!string.IsNullOrEmpty(cc.YAxisUnitName)) { sb.Append("(").Append(cc.YAxisUnitName).Append(")"); } sb.Append("\r\n"); info = sb.ToString(); sb.Clear(); } else { info = CursorFormat.Format <int>(cursor.YIndex); } if (!string.IsNullOrEmpty(info)) { _DrawCursor(g, info, new Point(cursor.Pt_x, cursor.Pt_y), cc.Pen, _AxesFont, cc.Brush, _DragRectBrush, _DestImage.Width, _DestImage.Height); } } } }
/* 绘制单条曲线 */ protected virtual void _DrawSingleCurve(Graphics g, int width, int height, ChartCurve1V cc) { Rectangle rect_grid = _GetGridRect(width, height); int chart_width = rect_grid.Width; int chart_height = rect_grid.Height; List <Point> pts = new List <Point>(); List <float> data_y = cc.YAxisData; if (data_y.Count < 2) { return; } cc._ChartCursors1V.Clear(); int start_index, stop_index; cc.GetYAxisStartStopIndex(_XAxisMinValueUsed, _XAxisMaxValueUsed, out start_index, out stop_index); float y_axis_max, y_axis_min; if (YAxisCombined) { y_axis_max = _YAxisMaxValueUsed; y_axis_min = _YAxisMinValueUsed; } else { y_axis_max = cc.YAxisMaxValueUsed; y_axis_min = cc.YAxisMinValueUsed; } for (int i = start_index; i <= stop_index && i < data_y.Count; ++i) { float x_v = i * cc.Delta; int pt_x = rect_grid.X + _GetXAxisPos(x_v, _XAxisMaxValueUsed, _XAxisMinValueUsed, rect_grid.Width); float y_v = data_y[i]; int pt_y = rect_grid.Y + _GetYAxisPos(y_v, y_axis_max, y_axis_min, rect_grid.Height); pts.Add(new Point(pt_x, pt_y)); ChartCursor1V cursor = new ChartCursor1V { Pt_x = pt_x, Pt_y = pt_y, YValue = y_v, Pt_count = 1, Y_max = y_v, Y_min = y_v, YIndex = i, }; if (!cc._ChartCursors1V.Keys.Contains(pt_x)) { cc._ChartCursors1V.Add(pt_x, cursor); } else { ChartCursor1V cursor_exist = cc._ChartCursors1V[pt_x]; cursor_exist.Pt_count++; cursor_exist.Y_max = (cursor_exist.Y_max >= y_v ? cursor_exist.Y_max : y_v); cursor_exist.Y_min = (cursor_exist.Y_min <= y_v ? cursor_exist.Y_min : y_v); } } if (pts.Count > 1) { g.DrawLines(cc.Pen, pts.ToArray()); if (pts.Count < rect_grid.Width / 2) { Rectangle r = new Rectangle(); r.Width = 4; r.Height = 4; pts.ForEach((Point pt) => { r.X = pt.X - 2; r.Y = pt.Y - 2; g.DrawRectangle(cc.Pen, r); }); } } else if (pts.Count == 1) { g.DrawRectangle(cc.Pen, new Rectangle(pts[0].X - 2, pts[0].Y - 2, 4, 4)); } }