void RenderPie(bool left, System.Drawing.Graphics g) { Pie pie = left ? _leftPie : _rightPie; Label firstLabel = null; Label lastLabel = null; float startAngle = 0F; for (int i = 0; i < pie.Blocks.Count; i++) { PieBlock block = pie.Blocks[i]; Label label = _labels.Find(p => p.Index == block.Index); if (label == null) { continue; } if (i == 0) { firstLabel = label; } lastLabel = label; g.FillPie(label.Brush, pie.X, pie.Y, pie.Width, pie.Height, startAngle, block.Percent); startAngle += block.Percent; } if (firstLabel == null) { firstLabel = new Label() { Index = 0, Color = System.Drawing.Color.Gray, Name = "" }; g.FillPie(firstLabel.Brush, pie.X, pie.Y, pie.Width, pie.Height, 0F, 1F); } g.DrawPie(new System.Drawing.Pen(firstLabel.Brush), pie.X, pie.Y, pie.Width, pie.Height, 0F, 360F); //bottom labels float bottomY = pie.Y + pie.Height + 15F; if (left) { float bottomX = pie.X + 4F; for (int i = 0; i < pie.Labels.Count; i++) { Label label = pie.Labels[i]; g.FillRectangle(label.Brush, bottomX, bottomY, Font.Height, Font.Height); bottomX += Font.Height + 3F; string text = label.Name; System.Drawing.SizeF textSize = g.MeasureString(text, _font); g.DrawString(text, _font, label.Brush, bottomX, bottomY + (_font.Height - textSize.Height) / 2F); bottomX += textSize.Width + 10F; if (!string.IsNullOrEmpty(label.Value)) { text = label.Value; bottomX -= 8F; textSize = g.MeasureString(text, _font); g.DrawString(text, _font, label.Brush, bottomX, bottomY + (_font.Height - textSize.Height) / 2F); bottomX += textSize.Width + 10F; } } } else { float bottomX = pie.X + pie.Width - 4F; for (int i = pie.Labels.Count - 1; i >= 0; i--) { Label label = pie.Labels[i]; string text = null; System.Drawing.SizeF textSize; if (!string.IsNullOrEmpty(label.Value)) { text = label.Value; textSize = g.MeasureString(text, _font); bottomX -= textSize.Width; g.DrawString(text, _font, label.Brush, bottomX, bottomY + (_font.Height - textSize.Height) / 2F); bottomX -= 3F; } text = label.Name; textSize = g.MeasureString(text, _font); bottomX -= textSize.Width; g.DrawString(text, _font, label.Brush, bottomX, bottomY + (_font.Height - textSize.Height) / 2F); bottomX -= 3F; bottomX -= Font.Height; g.FillRectangle(label.Brush, bottomX, bottomY, Font.Height, Font.Height); bottomX -= 10F; } } }