MTExample3_4.ChartStyle.AddLabels C# (CSharp) Method

AddLabels() private method

private AddLabels ( Graphics g ) : void
g System.Drawing.Graphics
return void
        void AddLabels(Graphics g)
        {
            float xOffset = chartArea.Width / 30.0f;
            float yOffset = chartArea.Height / 30.0f;
            CGSize labelFontSize = g.MeasureString ("A", LabelFont);
            CGSize titleFontSize = g.MeasureString ("A", TitleFont);

            // Add horizontal axis label:
            var aBrush = new SolidBrush(LabelFontColor);
            SizeF stringSize = g.MeasureString (XLabel, LabelFont);
            g.DrawString (XLabel, LabelFont, aBrush, new PointF (PlotArea.Left + PlotArea.Width / 2 - (int)stringSize.Width / 2, ChartArea.Bottom - (int)yOffset - (int)labelFontSize.Height));

            // Add y-axis label:
            var sFormat = new StringFormat ();
            sFormat.Alignment = StringAlignment.Center;
            stringSize = g.MeasureString (YLabel, LabelFont);
            // Save the state of the current Graphics object
            GraphicsState gState = g.Save ();
            g.TranslateTransform (xOffset, (float)(yOffset + titleFontSize.Height + yOffset / 3 + PlotArea.Height / 2));
            g.RotateTransform (-90);
            g.DrawString (YLabel, LabelFont, aBrush, 0, 0, sFormat);
            // Restore it:
            g.Restore (gState);

            // Add title:
            aBrush = new SolidBrush (TitleFontColor);
            stringSize = g.MeasureString (Title, TitleFont);
            if (Title.ToUpper () != "NO TITLE")
                g.DrawString (Title, TitleFont, aBrush, new PointF (PlotArea.Left + PlotArea.Width / 2 - (int)stringSize.Width / 2, ChartArea.Top + (int)yOffset));
            aBrush.Dispose ();
        }