public ChartCanvas(RectangleF rect) : base(rect) { ContentMode = UIViewContentMode.Redraw; this.AutoresizingMask = UIViewAutoresizing.All; this.BackColor = Color.Wheat; PlotPanel = new PlotPanel(rect); this.AddSubview(PlotPanel); // Subscribing to a paint eventhandler to drawingPanel: PlotPanel.Paint += new PaintEventHandler(PlotPanelPaint); cs = new ChartStyle(this); dc = new DataCollection(this); // Specify chart style parameters: cs.Title = "Chart of GE Stock"; cs.XTickOffset = 1; cs.XLimMin = -1f; cs.XLimMax = 20f; cs.YLimMin = 32f; cs.YLimMax = 36f; cs.XTick = 2f; cs.YTick = 0.5f; dc.StockChartType = DataCollection.StockChartTypeEnum.Candle; }
public ChartCanvas(RectangleF rect) : base(rect) { ContentMode = UIViewContentMode.Redraw; this.AutoresizingMask = UIViewAutoresizing.All; this.BackColor = Color.Wheat; PlotPanel = new PlotPanel(rect); this.AddSubview(PlotPanel); // Subscribing to a paint eventhandler to drawingPanel: PlotPanel.Paint += new PaintEventHandler(PlotPanelPaint); cs = new ChartStyle(this); dc = new DataCollection(this); // Specify chart style parameters: cs.Title = "Chart of GE Stock"; cs.XTickOffset = 1; cs.XLimMin = -1f; cs.XLimMax = 20f; cs.YLimMin = 32f; cs.YLimMax = 36f; cs.XTick = 2f; cs.YTick = 0.5f; dc.StockChartType = DataCollection.StockChartTypeEnum.Candle; }
public void AddStockChart(Graphics g, ChartStyle cs) { foreach (DataSeries ds in DataSeriesList) { Pen aPen = new Pen (ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; SolidBrush aBrush = new SolidBrush (ds.LineStyle.LineColor); SolidBrush whiteBrush = new SolidBrush (Color.White); float barLength = form1.PlotPanel.Width / (5 * ds.DataString.GetLength (1)); for (int i = 0; i < ds.DataString.GetLength(1); i++) { float[] stockdata = new float[4]; for (int j = 0; j < stockdata.Length; j++) { stockdata [j] = Convert.ToSingle (ds.DataString [j + 1, i]); } PointF ptHigh = cs.Point2D (new PointF (i, stockdata [1])); PointF ptLow = cs.Point2D (new PointF (i, stockdata [2])); PointF ptOpen = cs.Point2D (new PointF (i, stockdata [0])); PointF ptCLose = cs.Point2D (new PointF (i, stockdata [3])); PointF ptOpen1 = new PointF (ptOpen.X - barLength, ptOpen.Y); PointF ptClose1 = new PointF (ptCLose.X + barLength, ptCLose.Y); PointF ptOpen2 = new PointF (ptOpen.X + barLength, ptOpen.Y); PointF ptClose2 = new PointF (ptCLose.X - barLength, ptCLose.Y); // Draw Hi-Lo stock chart: if (StockChartType == StockChartTypeEnum.HiLo) { g.DrawLine (aPen, ptHigh, ptLow); } // Draw Hi-Li-Open-Close chart: else if (StockChartType == StockChartTypeEnum.HiLoOpenClose) { g.DrawLine (aPen, ptHigh, ptLow); g.DrawLine (aPen, ptOpen, ptOpen1); g.DrawLine (aPen, ptCLose, ptClose1); } // Draw candle chart: else if (stockChartType == StockChartTypeEnum.Candle) { PointF[] pts = new PointF[4]; pts [0] = ptOpen1; pts [1] = ptOpen2; pts [2] = ptClose1; pts [3] = ptClose2; g.DrawLine (aPen, ptHigh, ptLow); if (stockdata [0] > stockdata [3]) { g.FillPolygon (aBrush, pts); } else if (stockdata [0] < stockdata [3]) { g.FillPolygon (whiteBrush, pts); } g.DrawPolygon (aPen, pts); } } aPen.Dispose (); aBrush.Dispose (); whiteBrush.Dispose (); } }
public void AddStockChart(Graphics g, ChartStyle cs) { foreach (DataSeries ds in DataSeriesList) { Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness); aPen.DashStyle = ds.LineStyle.Pattern; SolidBrush aBrush = new SolidBrush(ds.LineStyle.LineColor); SolidBrush whiteBrush = new SolidBrush(Color.White); float barLength = form1.PlotPanel.Width / (5 * ds.DataString.GetLength(1)); for (int i = 0; i < ds.DataString.GetLength(1); i++) { float[] stockdata = new float[4]; for (int j = 0; j < stockdata.Length; j++) { stockdata [j] = Convert.ToSingle(ds.DataString [j + 1, i]); } PointF ptHigh = cs.Point2D(new PointF(i, stockdata [1])); PointF ptLow = cs.Point2D(new PointF(i, stockdata [2])); PointF ptOpen = cs.Point2D(new PointF(i, stockdata [0])); PointF ptCLose = cs.Point2D(new PointF(i, stockdata [3])); PointF ptOpen1 = new PointF(ptOpen.X - barLength, ptOpen.Y); PointF ptClose1 = new PointF(ptCLose.X + barLength, ptCLose.Y); PointF ptOpen2 = new PointF(ptOpen.X + barLength, ptOpen.Y); PointF ptClose2 = new PointF(ptCLose.X - barLength, ptCLose.Y); // Draw Hi-Lo stock chart: if (StockChartType == StockChartTypeEnum.HiLo) { g.DrawLine(aPen, ptHigh, ptLow); } // Draw Hi-Li-Open-Close chart: else if (StockChartType == StockChartTypeEnum.HiLoOpenClose) { g.DrawLine(aPen, ptHigh, ptLow); g.DrawLine(aPen, ptOpen, ptOpen1); g.DrawLine(aPen, ptCLose, ptClose1); } // Draw candle chart: else if (stockChartType == StockChartTypeEnum.Candle) { PointF[] pts = new PointF[4]; pts [0] = ptOpen1; pts [1] = ptOpen2; pts [2] = ptClose1; pts [3] = ptClose2; g.DrawLine(aPen, ptHigh, ptLow); if (stockdata [0] > stockdata [3]) { g.FillPolygon(aBrush, pts); } else if (stockdata [0] < stockdata [3]) { g.FillPolygon(whiteBrush, pts); } g.DrawPolygon(aPen, pts); } } aPen.Dispose(); aBrush.Dispose(); whiteBrush.Dispose(); } }