// for stock price data only. public bool replaceTable(int index, IStockDataTable table) { ChartData tmp = (ChartData)series[index]; if (tmp.style != ChartStyle.STOCKCANDLE) { return(false); } tmp.replace(this, table); return(true); }
private void drawData(Graphics g, ChartData cd, int start, int end) { if (cd.style == ChartStyle.STOCKCANDLE) { IStockDataTable table = (IStockDataTable)cd.table; int b = area.XPixelsPerGrids / 2; using (SolidBrush brush = new SolidBrush(cd.color)) { using (Pen pen = new Pen(cd.color)) { for (int x = start; x <= end; x++) { IStockPrice price = table[ScaleTypeX, x]; int h = price.end - price.start; int x2 = area.xpics(x) + b; if (h > 0) { g.DrawLine(pen, x2, area.ypics(price.high), x2, area.ypics(price.end)); g.DrawLine(pen, x2, area.ypics(price.start), x2, area.ypics(price.low)); g.DrawRectangle(pen, area.rect(x, price.end, 1, h)); } else { g.DrawLine(pen, x2, area.ypics(price.low), x2, area.ypics(price.high)); g.FillRectangle(brush, area.rect(x, price.start, 1, -h)); } } // for(x) } // using (pen) } // using (brush) } else { ILongDataTable table = (ILongDataTable)cd.table; switch (cd.style) { case ChartStyle.COLUMN: using (Pen pen = new Pen(cd.color)) { Rectangle[] colm = new Rectangle[end - start + 1]; int i = 0; for (int x = start; x <= end; x++) { Rectangle r = area.rect(x, 0, 1, table[ScaleTypeX, x]); r.Inflate(-1, 0); colm[i++] = r; } g.DrawRectangles(pen, colm); break; } case ChartStyle.AREA: using (SolidBrush brush = new SolidBrush(cd.color)) { Point[] poly = new Point[end - start + 3]; int i = 0; for (int x = start; x <= end; x++) { poly[i++] = area.point(x, table[ScaleTypeX, x]); } poly[i++] = area.point(end, 0); poly[i++] = area.point(start, 0); g.FillPolygon(brush, poly); break; } case ChartStyle.LINE: using (Pen pen = new Pen(cd.color)) { Point[] poly = new Point[end - start + 1]; int i = 0; for (int x = start; x <= end; x++) { poly[i++] = area.point(x, table[ScaleTypeX, x]); } g.DrawLines(pen, poly); break; } } // switch } // else }
public void addDataSource(IStockDataTable table, Color color) { series.Add(new ChartData(this, table, color, ChartStyle.STOCKCANDLE)); }