Esempio n. 1
0
        private void renderAxisLabel(Graphics graphics, int index, string label)
        {
            var measure = graphics.MeasureString(label, _style.AxisCaptionFont);
            var origin  = getPointOnLine(index, _style.AxisCaptionDistance + 1F);
            var point   = origin;
            var rect    = new RectangleF(point, measure);
            var mid     = chartMiddle;

            var pen = new Pen(Color.Red, 1F);

            // get corner of rectangle which would move the rect furtest away from the axis
            if (point.X == mid.X && point.Y < mid.Y)
            {
                point = rect.BottomCenter();
            }
            else if (point.X > mid.X && point.Y < mid.Y)
            {
                point = rect.BottomLeft();
            }
            else if (point.X > mid.X && point.Y == mid.Y)
            {
                point = rect.CenterLeft();
            }
            else if (point.X > mid.X && point.Y > mid.Y)
            {
                point = rect.TopLeft();
            }
            else if (point.X == mid.X && point.Y > mid.Y)
            {
                point = rect.TopCenter();
            }
            else if (point.X < mid.X && point.Y > mid.Y)
            {
                point = rect.TopRight();
            }
            else if (point.X < mid.X && point.Y == mid.Y)
            {
                point = rect.CenterRight();
            }
            else if (point.X < mid.X && point.Y < mid.Y)
            {
                point = rect.BottomRight();
            }

            // translate the rectangle to the new location
            rect.X += origin.X - point.X;
            rect.Y += origin.Y - point.Y;


            //graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
            //graphics.DrawCircle(pen, rect.TopCenter(), 3);
            //graphics.DrawCircle(pen, rect.TopRight(), 3);
            //graphics.DrawCircle(pen, rect.CenterRight(), 3);
            //graphics.DrawCircle(pen, rect.BottomRight(), 3);
            //graphics.DrawCircle(pen, rect.BottomCenter(), 3);
            //graphics.DrawCircle(pen, rect.BottomLeft(), 3);
            //graphics.DrawCircle(pen, rect.CenterLeft(), 3);
            //graphics.DrawCircle(pen, rect.TopLeft(), 3);

            graphics.DrawString(label, _style.AxisCaptionFont, new SolidBrush(_style.TextColor), rect);
        }