public DrawingView(CGRect rect)
            : base(rect)
        {
            ContentMode = UIViewContentMode.Redraw;
            AutoresizingMask = UIViewAutoresizing.All;
            BackColor = Color.Wheat;

            sc = new SubChart (this);
            sc.TotalChartBackColor = Color.White;
            sc.Margin = 20;
            sc.Rows = 2;
            sc.Cols = 2;

            dc1 = new DataCollection ();
            cs1 = new ChartStyle (this);
            cs1.TickFont = new Font ("Arial", 7f, FontStyle.Regular);
            cs1.TitleFont = new Font ("Arial", 10f, FontStyle.Regular);
            cs1.XLimMin = 0f;
            cs1.XLimMax = 7f;
            cs1.YLimMin = -1.5f;
            cs1.YLimMax = 1.5f;
            cs1.XTick = 1f;
            cs1.YTick = .5f;
            cs1.Title = "Sin(x)";

            // Sub-chart 2 (0, 1):
            dc2 = new DataCollection ();
            cs2 = new ChartStyle (this);
            cs2.TickFont = new Font ("Arial", 7f, FontStyle.Regular);
            cs2.TitleFont = new Font ("Arial", 10f, FontStyle.Regular);
            cs2.XLimMin = 0f;
            cs2.XLimMax = 7f;
            cs2.YLimMin = -1.5f;
            cs2.YLimMax = 1.5f;
            cs2.XTick = 1f;
            cs2.YTick = .5f;
            cs2.Title = "Cos(x)";

            // Sub-chart 3 (1, 0):
            dc3 = new DataCollection ();
            cs3 = new ChartStyle (this);
            cs3.TickFont = new Font ("Arial", 7f, FontStyle.Regular);
            cs3.TitleFont = new Font ("Arial", 10f, FontStyle.Regular);
            cs3.XLimMin = 0f;
            cs3.XLimMax = 7f;
            cs3.YLimMin = -.5f;
            cs3.YLimMax = 1.5f;
            cs3.XTick = 1f;
            cs3.YTick = .5f;
            cs3.Title = "Sin(x)^2";

            // Sub-chart 4 (1, 1):
            dc4 = new DataCollection ();
            cs4 = new ChartStyle (this);
            cs4.IsY2Axis = true;
            cs4.IsXGrid = false;
            cs4.IsYGrid = false;
            cs4.TickFont = new Font ("Arial", 7f, FontStyle.Regular);
            cs4.TitleFont = new Font ("Arial", 10f, FontStyle.Regular);
            cs4.XLimMin = 0f;
            cs4.XLimMax = 30f;
            cs4.YLimMin = -20f;
            cs4.YLimMax = 20f;
            cs4.XTick = 5f;
            cs4.YTick = 5f;
            cs4.Y2LimMin = 100f;
            cs4.Y2LimMax = 700f;
            cs4.Y2Tick = 100f;
            cs4.XLabel = "X Axis";
            cs4.YLabel = "Y Axis";
            cs4.Y2Label = "Y2 Axis";
            cs4.Title = "With Y2 Axis";
            lg = new Legend ();
            lg.IsLegendVisible = true;
            lg.LegendPosition = Legend.LegendPositionEnum.SouthEast;
        }
Beispiel #2
0
        void DrawLegend(Graphics g, float xCenter, float yCenter, float hWidth, float hHeight, DataCollection dc, ChartStyle cs)
        {
            float spacing = 8f;
            float textHeight = 8f;
            float htextHeight = textHeight / 2f;
            float lineLength = 30f;
            float hlineLength = lineLength / 2f;
            Rectangle legendRectangle;
            var aPen = new Pen (LegendBorderColor, 1f);
            var aBrush = new SolidBrush (LegendBackColor);

            if (isLegendVisible) {
                legendRectangle = new Rectangle ((int)xCenter - (int)hWidth,
                    (int)yCenter - (int)hHeight,
                    (int)(2.0f * hWidth), (int)(2.0f * hHeight));
                g.FillRectangle(aBrush, legendRectangle);
                if (IsBorderVisible)
                    g.DrawRectangle (aPen, legendRectangle);

                int n = 1;
                foreach (DataSeries ds in dc.DataSeriesList) {
                    // Draw lines and symbols:
                    float xSymbol = legendRectangle.X + spacing + hlineLength;
                    float xText = legendRectangle.X + 2 * spacing + lineLength;
                    float yText = legendRectangle.Y + n * spacing + (2 * n - 1) * htextHeight;
                    aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness);
                    aPen.DashStyle = ds.LineStyle.Pattern;
                    var ptStart = new PointF (legendRectangle.X + spacing, yText);
                    var ptEnd = new PointF (legendRectangle.X + spacing + lineLength, yText);

                    g.DrawLine (aPen, ptStart, ptEnd);
                    ds.SymbolStyle.DrawSymbol (g, new CGPoint(xSymbol, yText));
                    // Draw text:
                    var sFormat = new StringFormat {
                        Alignment = StringAlignment.Near
                    };
                    g.DrawString(ds.SeriesName, LegendFont, new SolidBrush(textColor), new PointF (xText, yText - 8), sFormat);
                    n++;
                }
            }
            aPen.Dispose ();
            aBrush.Dispose ();
        }
Beispiel #3
0
        public void AddLegend(Graphics g, DataCollection dc, ChartStyle cs)
        {
            if (dc.DataSeriesList.Count < 1)
                return;

            if (!IsLegendVisible)
                return;

            int numberOfDataSeries = dc.DataSeriesList.Count;
            string[] legendLabels = new string[dc.DataSeriesList.Count];
            int n = 0;
            foreach (DataSeries ds in dc.DataSeriesList) {
                legendLabels[n] = ds.SeriesName;
                n++;
            }

            float offSet = 10;
            float xc = 0f;
            float yc = 0f;
            CGSize size = g.MeasureString(legendLabels[0], LegendFont);
            var legendWidth = (float)size.Width;
            for (int i = 0; i < legendLabels.Length; i++) {
                size = g.MeasureString(legendLabels[i], LegendFont);
                var tempWidth = (float)size.Width;
                if (legendWidth < tempWidth)
                    legendWidth = tempWidth;
            }
            legendWidth = legendWidth + 50f;
            float hWidth = legendWidth / 2;
            float legendHeight = 18f * numberOfDataSeries;
            float hHeight = legendHeight / 2;

            switch (LegendPosition) {
                case LegendPositionEnum.East:
                    xc = cs.PlotArea.X + cs.PlotArea.Width - offSet - hWidth;
                    yc = cs.PlotArea.Y + cs.PlotArea.Height / 2;
                    break;
                case LegendPositionEnum.North:
                    xc = cs.PlotArea.X + cs.PlotArea.Width / 2;
                    yc = cs.PlotArea.Y + offSet + hHeight;
                    break;
                case LegendPositionEnum.NorthEast:
                    xc = cs.PlotArea.X + cs.PlotArea.Width - offSet - hWidth;
                    yc = cs.PlotArea.Y + offSet + hHeight;
                    break;
                case LegendPositionEnum.NorthWest:
                    xc = cs.PlotArea.X + offSet + hWidth;
                    yc = cs.PlotArea.Y + offSet + hHeight;
                    break;
                case LegendPositionEnum.South:
                    xc = cs.PlotArea.X + cs.PlotArea.Width / 2;
                    yc = cs.PlotArea.Y + cs.PlotArea.Height - offSet - hHeight;
                    break;
                case LegendPositionEnum.SouthEast:
                    xc = cs.PlotArea.X + cs.PlotArea.Width - offSet - hWidth;
                    yc = cs.PlotArea.Y + cs.PlotArea.Height - offSet - hHeight;
                    break;
                case LegendPositionEnum.SouthWest:
                    xc = cs.PlotArea.X + offSet + hWidth;
                    yc = cs.PlotArea.Y + cs.PlotArea.Height - offSet - hHeight;
                    break;
                case LegendPositionEnum.West:
                    xc = cs.PlotArea.X + offSet + hWidth;
                    yc = cs.PlotArea.Y + cs.PlotArea.Height / 2;
                    break;
            }
            DrawLegend (g, xc, yc, hWidth, hHeight, dc, cs);
        }
Beispiel #4
0
        public DrawingView(CGRect rect) : base(rect)
        {
            ContentMode      = UIViewContentMode.Redraw;
            AutoresizingMask = UIViewAutoresizing.All;
            BackColor        = Color.Wheat;

            sc = new SubChart(this);
            sc.TotalChartBackColor = Color.White;
            sc.Margin = 20;
            sc.Rows   = 2;
            sc.Cols   = 2;

            dc1           = new DataCollection();
            cs1           = new ChartStyle(this);
            cs1.TickFont  = new Font("Arial", 7f, FontStyle.Regular);
            cs1.TitleFont = new Font("Arial", 10f, FontStyle.Regular);
            cs1.XLimMin   = 0f;
            cs1.XLimMax   = 7f;
            cs1.YLimMin   = -1.5f;
            cs1.YLimMax   = 1.5f;
            cs1.XTick     = 1f;
            cs1.YTick     = .5f;
            cs1.Title     = "Sin(x)";

            // Sub-chart 2 (0, 1):
            dc2           = new DataCollection();
            cs2           = new ChartStyle(this);
            cs2.TickFont  = new Font("Arial", 7f, FontStyle.Regular);
            cs2.TitleFont = new Font("Arial", 10f, FontStyle.Regular);
            cs2.XLimMin   = 0f;
            cs2.XLimMax   = 7f;
            cs2.YLimMin   = -1.5f;
            cs2.YLimMax   = 1.5f;
            cs2.XTick     = 1f;
            cs2.YTick     = .5f;
            cs2.Title     = "Cos(x)";

            // Sub-chart 3 (1, 0):
            dc3           = new DataCollection();
            cs3           = new ChartStyle(this);
            cs3.TickFont  = new Font("Arial", 7f, FontStyle.Regular);
            cs3.TitleFont = new Font("Arial", 10f, FontStyle.Regular);
            cs3.XLimMin   = 0f;
            cs3.XLimMax   = 7f;
            cs3.YLimMin   = -.5f;
            cs3.YLimMax   = 1.5f;
            cs3.XTick     = 1f;
            cs3.YTick     = .5f;
            cs3.Title     = "Sin(x)^2";

            // Sub-chart 4 (1, 1):
            dc4                = new DataCollection();
            cs4                = new ChartStyle(this);
            cs4.IsY2Axis       = true;
            cs4.IsXGrid        = false;
            cs4.IsYGrid        = false;
            cs4.TickFont       = new Font("Arial", 7f, FontStyle.Regular);
            cs4.TitleFont      = new Font("Arial", 10f, FontStyle.Regular);
            cs4.XLimMin        = 0f;
            cs4.XLimMax        = 30f;
            cs4.YLimMin        = -20f;
            cs4.YLimMax        = 20f;
            cs4.XTick          = 5f;
            cs4.YTick          = 5f;
            cs4.Y2LimMin       = 100f;
            cs4.Y2LimMax       = 700f;
            cs4.Y2Tick         = 100f;
            cs4.XLabel         = "X Axis";
            cs4.YLabel         = "Y Axis";
            cs4.Y2Label        = "Y2 Axis";
            cs4.Title          = "With Y2 Axis";
            lg                 = new Legend();
            lg.IsLegendVisible = true;
            lg.LegendPosition  = Legend.LegendPositionEnum.SouthEast;
        }
Beispiel #5
0
        public void AddLegend(Graphics g, DataCollection dc, ChartStyle cs)
        {
            if (dc.DataSeriesList.Count < 1)
            {
                return;
            }

            if (!IsLegendVisible)
            {
                return;
            }

            int numberOfDataSeries = dc.DataSeriesList.Count;

            string[] legendLabels = new string[dc.DataSeriesList.Count];
            int      n            = 0;

            foreach (DataSeries ds in dc.DataSeriesList)
            {
                legendLabels[n] = ds.SeriesName;
                n++;
            }

            float  offSet      = 10;
            float  xc          = 0f;
            float  yc          = 0f;
            CGSize size        = g.MeasureString(legendLabels[0], LegendFont);
            var    legendWidth = (float)size.Width;

            for (int i = 0; i < legendLabels.Length; i++)
            {
                size = g.MeasureString(legendLabels[i], LegendFont);
                var tempWidth = (float)size.Width;
                if (legendWidth < tempWidth)
                {
                    legendWidth = tempWidth;
                }
            }
            legendWidth = legendWidth + 50f;
            float hWidth       = legendWidth / 2;
            float legendHeight = 18f * numberOfDataSeries;
            float hHeight      = legendHeight / 2;

            switch (LegendPosition)
            {
            case LegendPositionEnum.East:
                xc = cs.PlotArea.X + cs.PlotArea.Width - offSet - hWidth;
                yc = cs.PlotArea.Y + cs.PlotArea.Height / 2;
                break;

            case LegendPositionEnum.North:
                xc = cs.PlotArea.X + cs.PlotArea.Width / 2;
                yc = cs.PlotArea.Y + offSet + hHeight;
                break;

            case LegendPositionEnum.NorthEast:
                xc = cs.PlotArea.X + cs.PlotArea.Width - offSet - hWidth;
                yc = cs.PlotArea.Y + offSet + hHeight;
                break;

            case LegendPositionEnum.NorthWest:
                xc = cs.PlotArea.X + offSet + hWidth;
                yc = cs.PlotArea.Y + offSet + hHeight;
                break;

            case LegendPositionEnum.South:
                xc = cs.PlotArea.X + cs.PlotArea.Width / 2;
                yc = cs.PlotArea.Y + cs.PlotArea.Height - offSet - hHeight;
                break;

            case LegendPositionEnum.SouthEast:
                xc = cs.PlotArea.X + cs.PlotArea.Width - offSet - hWidth;
                yc = cs.PlotArea.Y + cs.PlotArea.Height - offSet - hHeight;
                break;

            case LegendPositionEnum.SouthWest:
                xc = cs.PlotArea.X + offSet + hWidth;
                yc = cs.PlotArea.Y + cs.PlotArea.Height - offSet - hHeight;
                break;

            case LegendPositionEnum.West:
                xc = cs.PlotArea.X + offSet + hWidth;
                yc = cs.PlotArea.Y + cs.PlotArea.Height / 2;
                break;
            }
            DrawLegend(g, xc, yc, hWidth, hHeight, dc, cs);
        }
Beispiel #6
0
        void DrawLegend(Graphics g, float xCenter, float yCenter, float hWidth, float hHeight, DataCollection dc, ChartStyle cs)
        {
            float     spacing     = 8f;
            float     textHeight  = 8f;
            float     htextHeight = textHeight / 2f;
            float     lineLength  = 30f;
            float     hlineLength = lineLength / 2f;
            Rectangle legendRectangle;
            var       aPen   = new Pen(LegendBorderColor, 1f);
            var       aBrush = new SolidBrush(LegendBackColor);

            if (isLegendVisible)
            {
                legendRectangle = new Rectangle((int)xCenter - (int)hWidth,
                                                (int)yCenter - (int)hHeight,
                                                (int)(2.0f * hWidth), (int)(2.0f * hHeight));
                g.FillRectangle(aBrush, legendRectangle);
                if (IsBorderVisible)
                {
                    g.DrawRectangle(aPen, legendRectangle);
                }

                int n = 1;
                foreach (DataSeries ds in dc.DataSeriesList)
                {
                    // Draw lines and symbols:
                    float xSymbol = legendRectangle.X + spacing + hlineLength;
                    float xText   = legendRectangle.X + 2 * spacing + lineLength;
                    float yText   = legendRectangle.Y + n * spacing + (2 * n - 1) * htextHeight;
                    aPen           = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness);
                    aPen.DashStyle = ds.LineStyle.Pattern;
                    var ptStart = new PointF(legendRectangle.X + spacing, yText);
                    var ptEnd   = new PointF(legendRectangle.X + spacing + lineLength, yText);

                    g.DrawLine(aPen, ptStart, ptEnd);
                    ds.SymbolStyle.DrawSymbol(g, new CGPoint(xSymbol, yText));
                    // Draw text:
                    var sFormat = new StringFormat {
                        Alignment = StringAlignment.Near
                    };
                    g.DrawString(ds.SeriesName, LegendFont, new SolidBrush(textColor), new PointF(xText, yText - 8), sFormat);
                    n++;
                }
            }
            aPen.Dispose();
            aBrush.Dispose();
        }