MTExample3_4.ChartStyle.AddChartStyle C# (CSharp) Method

AddChartStyle() public method

public AddChartStyle ( Graphics g ) : void
g System.Drawing.Graphics
return void
        public void AddChartStyle(Graphics g)
        {
            // Draw ChartArea and PlotArea:
            var aPen = new Pen(ChartBorderColor, 1f);
            var aBrush = new SolidBrush (ChartBackColor);
            g.FillRectangle (aBrush, ChartArea);
            g.DrawRectangle (aPen, ChartArea);
            aPen = new Pen (PlotBorderColor, 1f);
            aBrush = new SolidBrush (PlotBackColor);
            g.FillRectangle (aBrush, PlotArea);
            g.DrawRectangle (aPen, PlotArea);

            CGSize tickFontSize = g.MeasureString ("A", TickFont);
            // Create vertical gridlines:
            float fX, fY;
            if (IsYGrid == true) {
                aPen = new Pen(GridColor, 1f);
                aPen.DashStyle = GridPattern;
                for (fX = XLimMin + XTick; fX < XLimMax; fX += XTick) {
                    g.DrawLine(aPen, Point2D (new CGPoint (fX, YLimMin)), Point2D (new CGPoint (fX, YLimMax)));
                }
            }

            // Create horizontal gridlines:
            if (IsXGrid == true) {
                aPen = new Pen(GridColor, 1f);
                aPen.DashStyle = GridPattern;
                for (fY = YLimMin + YTick; fY < YLimMax; fY += YTick) {
                    g.DrawLine(aPen, Point2D (new CGPoint (XLimMin, fY)), Point2D (new CGPoint (XLimMax, fY)));
                }
            }

            // Create the x-axis tick marks:
            aBrush = new SolidBrush (TickFontColor);
            for (fX = XLimMin; fX <= XLimMax; fX += XTick) {
                PointF yAxisPoint = Point2D (new CGPoint (fX, YLimMin));
                g.DrawLine (Pens.Black, yAxisPoint, new PointF (yAxisPoint.X, yAxisPoint.Y - 5f));
                var sFormat = new StringFormat ();
                sFormat.Alignment = StringAlignment.Far;
                CGSize sizeXTick = g.MeasureString (fX.ToString (), TickFont);
                g.DrawString (fX.ToString(), TickFont, aBrush, new PointF ((float)(yAxisPoint.X + sizeXTick.Width / 2), yAxisPoint.Y + 4f), sFormat);
            }

            // Create the y-axis tick marks:
            for (fY = YLimMin; fY <= YLimMax; fY += YTick) {
                PointF xAxisPoint = Point2D (new CGPoint (XLimMin, fY));
                g.DrawLine (Pens.Black, xAxisPoint, new PointF (xAxisPoint.X + 5f, xAxisPoint.Y));
                var sFormat = new StringFormat ();
                sFormat.Alignment = StringAlignment.Far;
                g.DrawString (fY.ToString (), TickFont, aBrush, new PointF (xAxisPoint.X - 3f, (float)(xAxisPoint.Y - tickFontSize.Height / 2)), sFormat);
            }

            aPen.Dispose ();
            aBrush.Dispose ();
            AddLabels (g);
        }

Usage Example

Ejemplo n.º 1
0
        public override void Draw(CGRect rect)
        {
            var g = Graphics.FromCurrentContext();

            cs.ChartArea = ClientRectangle;
            AddData();
            SetPlotArea(g);
            cs.AddChartStyle(g);
            dc.AddLines(g, cs);
            lg.AddLegend(g, dc, cs);
            g.Dispose();
        }
All Usage Examples Of MTExample3_4.ChartStyle::AddChartStyle