Exemple #1
0
        /// <summary>
        /// Draws x- and y-axes.
        /// </summary>
        private void DrawAxes(Graphics g, Rectangle dataBounds, List <double> xTicks, List <double> yTicks)
        {
            double tickLabelHeight = TickLabelHeight(g);

            using (Brush brush = new SolidBrush(AxisPen.Color))
            {
                if (!String.IsNullOrEmpty(XAxis.Label))
                {
                    int cx = dataBounds.Left + dataBounds.Width / 2;
                    int xy = (int)Math.Round(dataBounds.Bottom + TickSize + tickLabelHeight + AxisMargin);
                    g.DrawString(XAxis.Label, AxisLabelFont, brush, cx, xy, AxisLabelFormat);
                }

                int tickY = (int)Math.Round(dataBounds.Bottom + TickSize);

                // Draw ticks
                foreach (double x in xTicks)
                {
                    int imgX = (int)XAxis.DataToImage(x, dataBounds.Left, dataBounds.Right);
                    g.DrawLine(AxisPen, imgX, dataBounds.Bottom, imgX, (int)Math.Round(dataBounds.Bottom + TickSize));

                    g.DrawString(GetTickLabel(x), TickLabelFont, brush, imgX, tickY, AxisLabelFormat);
                }

                if (!String.IsNullOrEmpty(YAxis.Label))
                {
                    int cy = dataBounds.Top + dataBounds.Height / 2;
                    int yx = (int)Math.Round(AxisMargin);

                    Matrix f = g.Transform;
                    try
                    {
                        g.TranslateTransform(yx, cy);
                        g.RotateTransform(-90);

                        g.DrawString(YAxis.Label, AxisLabelFont, brush, 0, 0, AxisLabelFormat);
                    }
                    finally
                    {
                        g.Transform = f;
                    }
                }

                int tickX = (int)Math.Round(dataBounds.Left - TickSize);
                foreach (double y in yTicks)
                {
                    int imgY = (int)YAxis.DataToImage(y, dataBounds.Top, dataBounds.Bottom);
                    g.DrawLine(AxisPen, (int)Math.Round(dataBounds.Left - TickSize), imgY, dataBounds.Left, imgY);

                    g.DrawString(GetTickLabel(y), TickLabelFont, brush, tickX, imgY, YTickFormat);
                }
            }
        }