Ejemplo n.º 1
0
        public ChartCanvas(RectangleF rect) : base(rect)
        {
            ContentMode           = UIViewContentMode.Redraw;
            this.AutoresizingMask = UIViewAutoresizing.All;
            this.BackColor        = Color.Wheat;

            PlotPanel = new PlotPanel(rect);

            this.AddSubview(PlotPanel);

            // Set Form1 size:
//			this.Width = 350;
//			this.Height = 300;
            // Subscribing to a paint eventhandler to drawingPanel:
            PlotPanel.Paint +=
                new PaintEventHandler(PlotPanelPaint);

            cs = new ChartStyle(this);
            dc = new DataCollection();
            // Specify chart style parameters:
            cs.Title = "Bar Chart";

            // Vertical
            cs.XLimMin = 0f;
            cs.XLimMax = 5f;
            cs.YLimMin = 0f;
            cs.YLimMax = 25f;
            cs.XTick   = 1f;
            cs.YTick   = 5f;

            cs.BarType = ChartStyle.BarTypeEnum.VerticalOverlay;
            //cs.BarType = ChartStyle.BarTypeEnum.VerticalStack;


            // Horizontal
            cs.XLimMin = 0f;
            cs.XLimMax = 25f;
            cs.YLimMin = 0f;
            cs.YLimMax = 5f;
            cs.XTick   = 5f;
            cs.YTick   = 1f;

            //cs.BarType = ChartStyle.BarTypeEnum.HorizontalOverlay;
            cs.BarType = ChartStyle.BarTypeEnum.HorizontalStack;
        }
        public ChartCanvas(RectangleF rect)
            : base(rect)
        {
            ContentMode = UIViewContentMode.Redraw;
            this.AutoresizingMask = UIViewAutoresizing.All;
            this.BackColor = Color.Wheat;

            PlotPanel = new PlotPanel(rect);

            this.AddSubview(PlotPanel);

            // Set Form1 size:
            //			this.Width = 350;
            //			this.Height = 300;
            // Subscribing to a paint eventhandler to drawingPanel:
            PlotPanel.Paint +=
                new PaintEventHandler(PlotPanelPaint);

            cs = new ChartStyle(this);
            dc = new DataCollection();
            // Specify chart style parameters:
            cs.Title = "Bar Chart";

            // Vertical
            cs.XLimMin = 0f;
            cs.XLimMax = 5f;
            cs.YLimMin = 0f;
            cs.YLimMax = 25f;
            cs.XTick = 1f;
            cs.YTick = 5f;

            cs.BarType = ChartStyle.BarTypeEnum.VerticalOverlay;
            //cs.BarType = ChartStyle.BarTypeEnum.VerticalStack;

            // Horizontal
            cs.XLimMin = 0f;
            cs.XLimMax = 25f;
            cs.YLimMin = 0f;
            cs.YLimMax = 5f;
            cs.XTick = 5f;
            cs.YTick = 1f;

            //cs.BarType = ChartStyle.BarTypeEnum.HorizontalOverlay;
            cs.BarType = ChartStyle.BarTypeEnum.HorizontalStack;
        }
Ejemplo n.º 3
0
        public ChartCanvas(CGRect rect)
            : base(rect)
        {
            ContentMode = UIViewContentMode.Redraw;
            AutoresizingMask = UIViewAutoresizing.All;
            BackColor = Color.Wheat;

            PlotPanel = new PlotPanel(rect);

            AddSubview (PlotPanel);
            PlotPanel.Paint += PlotPanelPaint;

            cs = new ChartStyle(this);
            dc = new DataCollection();
            // Specify chart style parameters:
            cs.Title = "Bar Chart";

            // Vertical
            cs.XLimMin = 0f;
            cs.XLimMax = 5f;
            cs.YLimMin = 0f;
            cs.YLimMax = 25f;
            cs.XTick = 1f;
            cs.YTick = 5f;

            cs.BarType = ChartStyle.BarTypeEnum.VerticalOverlay;

            // Horizontal
            cs.XLimMin = 0f;
            cs.XLimMax = 25f;
            cs.YLimMin = 0f;
            cs.YLimMax = 5f;
            cs.XTick = 5f;
            cs.YTick = 1f;

            //cs.BarType = ChartStyle.BarTypeEnum.HorizontalOverlay;
            cs.BarType = ChartStyle.BarTypeEnum.HorizontalStack;
        }
Ejemplo n.º 4
0
        public ChartCanvas(CGRect rect) : base(rect)
        {
            ContentMode      = UIViewContentMode.Redraw;
            AutoresizingMask = UIViewAutoresizing.All;
            BackColor        = Color.Wheat;

            PlotPanel = new PlotPanel(rect);

            AddSubview(PlotPanel);
            PlotPanel.Paint += PlotPanelPaint;

            cs = new ChartStyle(this);
            dc = new DataCollection();
            // Specify chart style parameters:
            cs.Title = "Bar Chart";

            // Vertical
            cs.XLimMin = 0f;
            cs.XLimMax = 5f;
            cs.YLimMin = 0f;
            cs.YLimMax = 25f;
            cs.XTick   = 1f;
            cs.YTick   = 5f;

            cs.BarType = ChartStyle.BarTypeEnum.VerticalOverlay;

            // Horizontal
            cs.XLimMin = 0f;
            cs.XLimMax = 25f;
            cs.YLimMin = 0f;
            cs.YLimMax = 5f;
            cs.XTick   = 5f;
            cs.YTick   = 1f;

            //cs.BarType = ChartStyle.BarTypeEnum.HorizontalOverlay;
            cs.BarType = ChartStyle.BarTypeEnum.HorizontalStack;
        }
        public void AddBars(Graphics g, ChartStyle cs, int numberOfDataSeries, int numberOfPoints)
        {
            // Draw bars:
            ArrayList temp = new ArrayList();

            float[] tempy  = new float[numberOfPoints];
            PointF  temppt = new PointF();
            int     n      = 0;

            foreach (DataSeries ds in DataSeriesList)
            {
                Pen        aPen   = new Pen(ds.BarStyle.BorderColor, ds.BarStyle.BorderThickness);
                SolidBrush aBrush = new SolidBrush(ds.BarStyle.FillColor);
                aPen.DashStyle = ds.BarStyle.BorderPattern;
                PointF[] pts = new PointF[4];
                PointF   pt;
                float    width;
                if (cs.BarType == ChartStyle.BarTypeEnum.Vertical)
                {
                    if (numberOfDataSeries == 1)
                    {
                        width = cs.XTick * ds.BarStyle.BarWidth;
                        for (int i = 0; i < ds.PointList.Count; i++)
                        {
                            pt = (PointF)ds.PointList[i];
                            float x = pt.X - cs.XTick / 2;
                            pts[0] = cs.Point2D(new PointF(x - width / 2, 0));
                            pts[1] = cs.Point2D(new PointF(x + width / 2, 0));
                            pts[2] = cs.Point2D(new PointF(x + width / 2, pt.Y));
                            pts[3] = cs.Point2D(new PointF(x - width / 2, pt.Y));
                            g.FillPolygon(aBrush, pts);
                            g.DrawPolygon(aPen, pts);
                        }
                    }
                    else if (numberOfDataSeries > 1)
                    {
                        width = 0.7f * cs.XTick;
                        for (int i = 0; i < ds.PointList.Count; i++)
                        {
                            pt = (PointF)ds.PointList[i];
                            float w1    = width / numberOfDataSeries;
                            float w     = ds.BarStyle.BarWidth * w1;
                            float space = (w1 - w) / 2;
                            float x     = pt.X - cs.XTick / 2;
                            pts[0] = cs.Point2D(new PointF(
                                                    x - width / 2 + space + n * w1, 0));
                            pts[1] = cs.Point2D(new PointF(
                                                    x - width / 2 + space + n * w1 + w, 0));
                            pts[2] = cs.Point2D(new PointF(
                                                    x - width / 2 + space + n * w1 + w, pt.Y));
                            pts[3] = cs.Point2D(new PointF(
                                                    x - width / 2 + space + n * w1, pt.Y));
                            g.FillPolygon(aBrush, pts);
                            g.DrawPolygon(aPen, pts);
                        }
                    }
                }
                else if (cs.BarType == ChartStyle.BarTypeEnum.VerticalOverlay &&
                         numberOfDataSeries > 1)
                {
                    width = cs.XTick * ds.BarStyle.BarWidth;
                    width = width / (float)Math.Pow(2, n);
                    for (int i = 0; i < ds.PointList.Count; i++)
                    {
                        pt = (PointF)ds.PointList[i];
                        float x = pt.X - cs.XTick / 2;
                        pts[0] = cs.Point2D(new PointF(x - width / 2, 0));
                        pts[1] = cs.Point2D(new PointF(x + width / 2, 0));
                        pts[2] = cs.Point2D(new PointF(x + width / 2, pt.Y));
                        pts[3] = cs.Point2D(new PointF(x - width / 2, pt.Y));
                        g.FillPolygon(aBrush, pts);
                        g.DrawPolygon(aPen, pts);
                    }
                }
                else if (cs.BarType == ChartStyle.BarTypeEnum.VerticalStack &&
                         numberOfDataSeries > 1)
                {
                    width = cs.XTick * ds.BarStyle.BarWidth;
                    for (int i = 0; i < ds.PointList.Count; i++)
                    {
                        pt = (PointF)ds.PointList[i];
                        if (temp.Count > 0)
                        {
                            tempy[i] = tempy[i] + ((PointF)temp[i]).Y;
                        }
                        float x = pt.X - cs.XTick / 2;
                        pts[0] = cs.Point2D(new PointF(x - width / 2, 0 + tempy[i]));
                        pts[1] = cs.Point2D(new PointF(x + width / 2, 0 + tempy[i]));
                        pts[2] = cs.Point2D(new PointF(x + width / 2, pt.Y + tempy[i]));
                        pts[3] = cs.Point2D(new PointF(x - width / 2, pt.Y + tempy[i]));

                        g.FillPolygon(aBrush, pts);
                        g.DrawPolygon(aPen, pts);
                    }
                    temp = ds.PointList;
                }

                else if (cs.BarType == ChartStyle.BarTypeEnum.Horizontal)
                {
                    if (numberOfDataSeries == 1)
                    {
                        width = cs.YTick * ds.BarStyle.BarWidth;
                        for (int i = 0; i < ds.PointList.Count; i++)
                        {
                            temppt = (PointF)ds.PointList[i];
                            pt     = new PointF(temppt.Y, temppt.X);
                            float y = pt.Y - cs.YTick / 2;
                            pts[0] = cs.Point2D(new PointF(0, y - width / 2));
                            pts[1] = cs.Point2D(new PointF(0, y + width / 2));
                            pts[2] = cs.Point2D(new PointF(pt.X, y + width / 2));
                            pts[3] = cs.Point2D(new PointF(pt.X, y - width / 2));
                            g.FillPolygon(aBrush, pts);
                            g.DrawPolygon(aPen, pts);
                        }
                    }
                    else if (numberOfDataSeries > 1)
                    {
                        width = 0.7f * cs.YTick;
                        for (int i = 0; i < ds.PointList.Count; i++)
                        {
                            temppt = (PointF)ds.PointList[i];
                            pt     = new PointF(temppt.Y, temppt.X);
                            float w1    = width / numberOfDataSeries;
                            float w     = ds.BarStyle.BarWidth * w1;
                            float space = (w1 - w) / 2;
                            float y     = pt.Y - cs.YTick / 2;
                            pts[0] = cs.Point2D(new PointF(0,
                                                           y - width / 2 + space + n * w1));
                            pts[1] = cs.Point2D(new PointF(0,
                                                           y - width / 2 + space + n * w1 + w));
                            pts[2] = cs.Point2D(new PointF(pt.X,
                                                           y - width / 2 + space + n * w1 + w));
                            pts[3] = cs.Point2D(new PointF(pt.X,
                                                           y - width / 2 + space + n * w1));
                            g.FillPolygon(aBrush, pts);
                            g.DrawPolygon(aPen, pts);
                        }
                    }
                }
                else if (cs.BarType == ChartStyle.BarTypeEnum.HorizontalOverlay &&
                         numberOfDataSeries > 1)
                {
                    width = cs.YTick * ds.BarStyle.BarWidth;
                    width = width / (float)Math.Pow(2, n);
                    for (int i = 0; i < ds.PointList.Count; i++)
                    {
                        temppt = (PointF)ds.PointList[i];
                        pt     = new PointF(temppt.Y, temppt.X);
                        float y = pt.Y - cs.YTick / 2;
                        pts[0] = cs.Point2D(new PointF(0, y - width / 2));
                        pts[1] = cs.Point2D(new PointF(0, y + width / 2));
                        pts[2] = cs.Point2D(new PointF(pt.X, y + width / 2));
                        pts[3] = cs.Point2D(new PointF(pt.X, y - width / 2));
                        g.FillPolygon(aBrush, pts);
                        g.DrawPolygon(aPen, pts);
                    }
                }
                else if (cs.BarType == ChartStyle.BarTypeEnum.HorizontalStack &&
                         numberOfDataSeries > 1)
                {
                    {
                        width = cs.YTick * ds.BarStyle.BarWidth;
                        for (int i = 0; i < ds.PointList.Count; i++)
                        {
                            temppt = (PointF)ds.PointList[i];
                            pt     = new PointF(temppt.Y, temppt.X);
                            if (temp.Count > 0)
                            {
                                temppt   = (PointF)temp[i];
                                tempy[i] = tempy[i] + temppt.Y;
                            }
                            float y = pt.Y - cs.YTick / 2;
                            pts[0] = cs.Point2D(new PointF(0 + tempy[i], y - width / 2));
                            pts[1] = cs.Point2D(new PointF(0 + tempy[i], y + width / 2));
                            pts[2] = cs.Point2D(new PointF(pt.X + tempy[i], y + width / 2));
                            pts[3] = cs.Point2D(new PointF(pt.X + tempy[i], y - width / 2));

                            g.FillPolygon(aBrush, pts);
                            g.DrawPolygon(aPen, pts);
                        }
                        temp = ds.PointList;
                    }
                }
                n++;
                aPen.Dispose();
            }
        }
Ejemplo n.º 6
0
        public void AddBars(Graphics g, ChartStyle cs, int numberOfDataSeries, int numberOfPoints)
        {
            // Draw bars:
            var temp = new ArrayList ();
            float[] tempy = new float[numberOfPoints];
            var temppt = new CGPoint ();
            int n = 0;
            foreach (DataSeries ds in DataSeriesList) {
                var aPen = new Pen (ds.BarStyle.BorderColor, ds.BarStyle.BorderThickness);
                var aBrush = new SolidBrush (ds.BarStyle.FillColor);
                aPen.DashStyle = ds.BarStyle.BorderPattern;
                var pts = new PointF[4];
                CGPoint pt;
                float width;
                if (cs.BarType == ChartStyle.BarTypeEnum.Vertical) {
                    if (numberOfDataSeries == 1) {
                        width = cs.XTick * ds.BarStyle.BarWidth;
                        for (int i = 0; i < ds.PointList.Count; i++) {
                            pt = (CGPoint)ds.PointList[i];
                            nfloat x = pt.X - cs.XTick / 2;
                            pts[0] = cs.Point2D (new CGPoint (x - width / 2, 0));
                            pts[1] = cs.Point2D (new CGPoint (x + width / 2, 0));
                            pts[2] = cs.Point2D (new CGPoint (x + width / 2, pt.Y));
                            pts[3] = cs.Point2D (new CGPoint (x - width / 2, pt.Y));
                            g.FillPolygon (aBrush, pts);
                            g.DrawPolygon (aPen, pts);
                        }
                    } else if (numberOfDataSeries > 1) {
                        width = 0.7f * cs.XTick;
                        for (int i = 0; i < ds.PointList.Count; i++) {
                            pt = (CGPoint)ds.PointList[i];
                            float w1 = width / numberOfDataSeries;
                            float w = ds.BarStyle.BarWidth * w1;
                            float space = (w1 - w) / 2;
                            nfloat x = pt.X - cs.XTick / 2;
                            pts[0] = cs.Point2D(new CGPoint(
                                x - width / 2 + space + n * w1, 0));
                            pts[1] = cs.Point2D(new CGPoint(
                                x - width / 2 + space + n * w1 + w, 0));
                            pts[2] = cs.Point2D(new CGPoint(
                                x - width / 2 + space + n * w1 + w, pt.Y));
                            pts[3] = cs.Point2D(new CGPoint(
                                x - width / 2 + space + n * w1, pt.Y));
                            g.FillPolygon(aBrush, pts);
                            g.DrawPolygon(aPen, pts);
                        }
                    }
                } else if (cs.BarType == ChartStyle.BarTypeEnum.VerticalOverlay && numberOfDataSeries > 1) {
                    width = cs.XTick * ds.BarStyle.BarWidth;
                    width = width / (float)Math.Pow(2, n);
                    for (int i = 0; i < ds.PointList.Count; i++) {
                        pt = (CGPoint)ds.PointList[i];
                        nfloat x = pt.X - cs.XTick / 2;
                        pts[0] = cs.Point2D(new CGPoint(x - width / 2, 0));
                        pts[1] = cs.Point2D(new CGPoint(x + width / 2, 0));
                        pts[2] = cs.Point2D(new CGPoint(x + width / 2, pt.Y));
                        pts[3] = cs.Point2D(new CGPoint(x - width / 2, pt.Y));
                        g.FillPolygon(aBrush, pts);
                        g.DrawPolygon(aPen, pts);
                    }
                } else if (cs.BarType == ChartStyle.BarTypeEnum.VerticalStack && numberOfDataSeries > 1) {
                    width = cs.XTick * ds.BarStyle.BarWidth;
                    for (int i = 0; i < ds.PointList.Count; i++) {
                        pt = (CGPoint)ds.PointList[i];
                        if (temp.Count > 0)
                            tempy[i] = (float)(tempy[i] + ((CGPoint)temp[i]).Y);
                        nfloat x = pt.X - cs.XTick / 2;
                        pts[0] = cs.Point2D (new CGPoint (x - width / 2, 0 + tempy[i]));
                        pts[1] = cs.Point2D (new CGPoint (x + width / 2, 0 + tempy[i]));
                        pts[2] = cs.Point2D (new CGPoint (x + width / 2, pt.Y + tempy[i]));
                        pts[3] = cs.Point2D (new CGPoint (x - width / 2, pt.Y + tempy[i]));

                        g.FillPolygon (aBrush, pts);
                        g.DrawPolygon (aPen, pts);
                    }
                    temp = ds.PointList;
                } else if (cs.BarType == ChartStyle.BarTypeEnum.Horizontal) {
                    if (numberOfDataSeries == 1) {
                        width = cs.YTick * ds.BarStyle.BarWidth;
                        for (int i = 0; i < ds.PointList.Count; i++) {
                            temppt = (CGPoint)ds.PointList[i];
                            pt = new CGPoint(temppt.Y, temppt.X);
                            nfloat y = pt.Y - cs.YTick / 2;
                            pts[0] = cs.Point2D (new CGPoint (0, y - width / 2));
                            pts[1] = cs.Point2D (new CGPoint (0, y + width / 2));
                            pts[2] = cs.Point2D (new CGPoint (pt.X, y + width / 2));
                            pts[3] = cs.Point2D (new CGPoint (pt.X, y - width / 2));
                            g.FillPolygon (aBrush, pts);
                            g.DrawPolygon (aPen, pts);
                        }
                    } else if (numberOfDataSeries > 1) {
                        width = 0.7f * cs.YTick;
                        for (int i = 0; i < ds.PointList.Count; i++) {
                            temppt = (CGPoint)ds.PointList[i];
                            pt = new CGPoint(temppt.Y, temppt.X);
                            float w1 = width / numberOfDataSeries;
                            float w = ds.BarStyle.BarWidth * w1;
                            float space = (w1 - w) / 2;
                            nfloat y = pt.Y - cs.YTick / 2;
                            pts[0] = cs.Point2D(new CGPoint(0,
                                y - width / 2 + space + n * w1));
                            pts[1] = cs.Point2D(new CGPoint(0,
                                y - width / 2 + space + n * w1 + w));
                            pts[2] = cs.Point2D(new CGPoint(pt.X,
                                y - width / 2 + space + n * w1 + w));
                            pts[3] = cs.Point2D(new CGPoint(pt.X,
                                y - width / 2 + space + n * w1));
                            g.FillPolygon(aBrush, pts);
                            g.DrawPolygon(aPen, pts);
                        }
                    }
                } else if (cs.BarType == ChartStyle.BarTypeEnum.HorizontalOverlay && numberOfDataSeries > 1) {
                    width = cs.YTick * ds.BarStyle.BarWidth;
                    width = width / (float)Math.Pow(2, n);
                    for (int i = 0; i < ds.PointList.Count; i++) {
                        temppt = (CGPoint)ds.PointList[i];
                        pt = new CGPoint(temppt.Y, temppt.X);
                        nfloat y = pt.Y - cs.YTick / 2;
                        pts[0] = cs.Point2D(new CGPoint(0, y - width / 2));
                        pts[1] = cs.Point2D(new CGPoint(0, y + width / 2));
                        pts[2] = cs.Point2D(new CGPoint(pt.X, y + width / 2));
                        pts[3] = cs.Point2D(new CGPoint(pt.X, y - width / 2));
                        g.FillPolygon(aBrush, pts);
                        g.DrawPolygon(aPen, pts);
                    }
                } else if (cs.BarType == ChartStyle.BarTypeEnum.HorizontalStack && numberOfDataSeries > 1) {
                    width = cs.YTick * ds.BarStyle.BarWidth;
                    for (int i = 0; i < ds.PointList.Count; i++) {
                        temppt = (CGPoint)ds.PointList[i];
                        pt = new CGPoint(temppt.Y, temppt.X);
                        if (temp.Count > 0) {
                            temppt = (CGPoint)temp[i];
                            tempy[i] = (float)(tempy[i] + temppt.Y);
                        }
                        nfloat y = pt.Y - cs.YTick / 2;
                        pts[0] = cs.Point2D (new CGPoint (0 + tempy[i], y - width / 2));
                        pts[1] = cs.Point2D (new CGPoint (0 + tempy[i], y + width / 2));
                        pts[2] = cs.Point2D (new CGPoint (pt.X + tempy[i], y + width / 2));
                        pts[3] = cs.Point2D (new CGPoint (pt.X + tempy[i], y - width / 2));

                        g.FillPolygon (aBrush, pts);
                        g.DrawPolygon (aPen, pts);
                    }
                    temp = ds.PointList;
                }
                n++;
                aPen.Dispose ();
            }
        }