protected override void DrawCore(Painter painter, ChartData data) { base.DrawCore(painter, data); if (data != null) { PaintArguments paintArguments = new PaintArguments(painter, data, ChartMargin); int start = paintArguments.AxisXLocation; try { float tmpY = painter.Height - paintArguments.AxisYLocation; int interval = CalculateInterval(painter, data); float ratio = paintArguments.Ratio; foreach (DataSeries dataSeries in data.Series) { painter.DrawString(dataSeries.Name, Style, new ChartPoint(start + interval, tmpY + 2)); foreach (DataPoint dataPoint in dataSeries.Point) { start += interval; if (dataPoint.IsValid == true) { ChartPoint[] rectPoint = new ChartPoint[4]; float y = dataPoint.Value / ratio; rectPoint[0] = new ChartPoint(start, tmpY - 1); rectPoint[1] = new ChartPoint(start, tmpY - y); rectPoint[2] = new ChartPoint(start + interval, tmpY - y); rectPoint[3] = new ChartPoint(start + interval, tmpY - 1); Style.CurrentColor = Style.ColorList[dataSeries.Point.IndexOf(dataPoint)]; painter.DrawPolygon(Style, rectPoint); if (interval > 10) { painter.DrawString(dataPoint.Value.ToString(), Style, new ChartPoint(start, tmpY - y - 15)); } } } start += interval; } } catch (IndexOutOfRangeException exception) { exception.Source = "Check the Painter whether is error./n Check the data source whether is error."; throw exception; } } }
private void DrawHorizontalGrid(Painter painter, ChartData data) { PaintArguments paintArguments = new PaintArguments(painter, data, chartMargin); float value = data.CalculateMaxValue(); float height = 20 / paintArguments.Ratio; ChartPoint[] points = new ChartPoint[2]; ChartPoint point = new ChartPoint(); float tmpX = paintArguments.AxisXLocation; if (value < height) { //Data max value is too small, so the offset is small for (int i = 0; i < value; i++) { float tmpY = painter.Height - i / paintArguments.Ratio - paintArguments.AxisYLocation; //One line-one string points[0] = new ChartPoint(tmpX, tmpY); points[1] = new ChartPoint(tmpX + paintArguments.AxisWidth, tmpY); painter.DrawLine(style, points, LineType.DotLine); point = new ChartPoint(tmpX - 30, tmpY - 2); painter.DrawString(i.ToString(), style, point); } } else { float tmp = painter.Height - paintArguments.AxisYLocation; //Normal offset for (int i = 0; i < paintArguments.AxisHeight / height; i++) { float tmpY = tmp - i * height; points[0] = new ChartPoint(tmpX, tmpY); points[1] = new ChartPoint(tmpX + paintArguments.AxisWidth, tmpY); painter.DrawLine(style, points, LineType.DotLine); point = new ChartPoint(tmpX - 30, tmpY - 2); painter.DrawString(((int)(i * height * paintArguments.Ratio)).ToString(), style, point); } } }
private void DrawLegend(Painter painter, string[] legends) { //Four points to draw rectangle ChartPoint[] rectanglePoint = new ChartPoint[4]; ChartPoint labelPoint; PaintArguments paintArguments = new PaintArguments(painter, null, chartMargin); float tmpX = paintArguments.AxisXLocation + paintArguments.AxisWidth + 15; for (int i = 0; i < legends.Length; i++) { //Set four points to draw legend rectangle float tmpY = painter.Height - paintArguments.AxisYLocation - paintArguments.AxisHeight + i * 10; rectanglePoint[0] = new ChartPoint(tmpX, tmpY); rectanglePoint[1] = new ChartPoint(tmpX + 6, tmpY); rectanglePoint[2] = new ChartPoint(tmpX + 6, tmpY + 5); rectanglePoint[3] = new ChartPoint(tmpX, tmpY + 5); style.CurrentColor = style.ColorList[i]; painter.DrawPolygon(style, rectanglePoint); //Set point to draw legend string labelPoint = new ChartPoint(tmpX + 8, tmpY - 5); painter.DrawString(legends[i], style, labelPoint); } }