MTExample4_1.ChartStyle.SetChartArea C# (CSharp) Method

SetChartArea() public method

public SetChartArea ( Graphics g ) : void
g System.Drawing.Graphics
return void
        public void SetChartArea(Graphics g)
        {
            SetPlotPanel (g);
            // Draw chart area:
            var aPen = new Pen (ChartBorderColor, 1f);
            var aBrush = new SolidBrush (ChartBackColor);
            CGSize tickFontSize = g.MeasureString("A", TickFont);
            g.FillRectangle (aBrush, ChartArea);
            g.DrawRectangle (aPen, ChartArea);

            // Create the x-axis tick labels:
            aBrush = new SolidBrush(TickFontColor);
            float xm = XLimMin + XTickOffset;
            float xticklabel = 0f;
            if (BarType == BarTypeEnum.Vertical || BarType == BarTypeEnum.VerticalOverlay || BarType == BarTypeEnum.VerticalStack) {
                xm = XTickOffset + XLimMin + XTick / 2;
                xticklabel = XTick / 2;
            }

            for (float fX = xm; fX <= XLimMax; fX += XTick) {
                var yAxisPoint = Point2D (new CGPoint (fX, YLimMin));
                var sFormat = new StringFormat {
                    Alignment = StringAlignment.Center
                };
                g.DrawString ((fX + xticklabel).ToString (), TickFont, aBrush, new PointF (form1.PlotPanel.Left + yAxisPoint.X, form1.PlotPanel.Top + yAxisPoint.Y + 4f), sFormat);
            }

            // Create the y-axis tick labels:
            float ym = YLimMin + YTickOffset;
            float yticklabel = 0f;
            if (BarType == BarTypeEnum.Horizontal || BarType == BarTypeEnum.HorizontalOverlay || BarType == BarTypeEnum.HorizontalStack) {
                ym = YTickOffset + YLimMin + YTick / 2;
                yticklabel = YTick / 2;
            }

            for (float fY = ym; fY <= YLimMax; fY += YTick) {
                Point xAxisPoint = Point2D (new CGPoint(XLimMin, fY));
                var sFormat = new StringFormat {
                    Alignment = StringAlignment.Far
                };
                g.DrawString ((fY + yticklabel).ToString (), TickFont, aBrush,
                    new PointF (form1.PlotPanel.Left + xAxisPoint.X - 3f, (float)(form1.PlotPanel.Top + xAxisPoint.Y - tickFontSize.Height / 2)), sFormat);
            }

            AddLabels (g);
        }

Usage Example

Ejemplo n.º 1
0
        public override void Draw(RectangleF dirtyRect)
        {
            Graphics g = Graphics.FromCurrentContext();

            cs.ChartArea = this.ClientRectangle;
            cs.SetChartArea(g);
        }
All Usage Examples Of MTExample4_1.ChartStyle::SetChartArea