private void DrawLegend(Graphics g, float xCenter, float yCenter,
                                float hWidth, float hHeight, DataSeries ds, ChartStyle cs)
        {
            float      spacing     = 8.0f;
            float      textHeight  = 8.0f;
            float      htextHeight = textHeight / 2.0f;
            float      lineLength  = 12.0f;
            float      hlineLength = lineLength / 2.0f;
            Rectangle  legendRectangle;
            Pen        aPen   = new Pen(LegendBorderColor, 1f);
            SolidBrush 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);
                }

                for (int i = 0; i < ds.DataList.Count; i++)
                {
                    float xSymbol = legendRectangle.X + spacing + hlineLength;
                    float xText   = legendRectangle.X + 2 * spacing + lineLength;
                    float yText   = legendRectangle.Y + (i + 1) * spacing +
                                    (2 * i + 1) * htextHeight;
                    aPen = new Pen(ds.BorderColor, ds.BorderThickness);
                    Color fillColor = Color.FromArgb(ds.CMap[i, 0], ds.CMap[i, 1],
                                                     ds.CMap[i, 2], ds.CMap[i, 3]);
                    aBrush = new SolidBrush(fillColor);
                    // Draw symbols:
                    float    hsize = 5f;
                    PointF[] pts   = new PointF[4];
                    pts[0] = new PointF(xSymbol - hsize, yText - hsize);
                    pts[1] = new PointF(xSymbol + hsize, yText - hsize);
                    pts[2] = new PointF(xSymbol + hsize, yText + hsize);
                    pts[3] = new PointF(xSymbol - hsize, yText + hsize);
                    g.FillPolygon(aBrush, pts);
                    g.DrawPolygon(aPen, pts);
                    // Draw text:
                    StringFormat sFormat = new StringFormat();
                    sFormat.Alignment = StringAlignment.Near;
                    g.DrawString((string)ds.LabelList[i], LegendFont,
                                 new SolidBrush(TextColor),
                                 new PointF(xText, yText - 8), sFormat);
                }
            }
            aPen.Dispose();
            aBrush.Dispose();
        }
        /*public void AddLabel(string str)
         * {
         *  labelList.Clear();
         *  labelList.Add(str);
         * }
         *
         * public void AddExplode(int nOffset)
         * {
         *  explodeList.Clear();
         *  explodeList.Add(nOffset);
         * }*/

        public void AddPie(Graphics g, ChartStyle cs)
        {
            SolidBrush aBrush = new SolidBrush(Color.Black);
            Pen        aPen   = new Pen(BorderColor);
            int        nData  = DataList.Count;
            float      fSum   = 0;

            for (int i = 0; i < nData; i++)
            {
                fSum = fSum + (float)DataList[i];
            }
            float     startAngle = 0;
            float     sweepAngle = 0;
            Rectangle rect       = cs.SetPieArea();

            for (int i = 0; i < nData; i++)
            {
                Color fillColor = Color.FromArgb(CMap[i, 0], CMap[i, 1],
                                                 CMap[i, 2], CMap[i, 3]);
                aBrush = new SolidBrush(fillColor);
                int explode = (int)ExplodeList[i];

                if (fSum < 1)
                {
                    startAngle = startAngle + sweepAngle;
                    sweepAngle = 360 * (float)DataList[i];
                }
                else if (fSum >= 1)
                {
                    startAngle = startAngle + sweepAngle;
                    sweepAngle = 360 * (float)DataList[i] / fSum;
                }

                int xshift = (int)(explode * Math.Cos((startAngle +
                                                       sweepAngle / 2) * Math.PI / 180));
                int yshift = (int)(explode * Math.Sin((startAngle +
                                                       sweepAngle / 2) * Math.PI / 180));
                Rectangle rect1 = new Rectangle(rect.X + xshift, rect.Y + yshift,
                                                rect.Width, rect.Height);
                g.FillPie(aBrush, rect1, startAngle, sweepAngle);
                g.DrawPie(aPen, rect1, startAngle, sweepAngle);
            }
        }
        public void AddLegend(Graphics g, DataSeries ds, ChartStyle cs)
        {
            if (ds.DataList.Count < 1)
            {
                return;
            }
            if (!IsLegendVisible)
            {
                return;
            }
            int numberOfDataValues = ds.DataList.Count;

            string[] legendLabels = new string[ds.LabelList.Count];
            for (int i = 0; i < ds.LabelList.Count; i++)
            {
                legendLabels[i] = (string)ds.LabelList[i];
            }
            // float offSet = 20;
            float xc          = 0f;
            float yc          = 0f;
            SizeF size        = g.MeasureString(legendLabels[0], LegendFont);
            float legendWidth = size.Width;

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

            Rectangle rect = cs.SetPieArea();

            xc = rect.X + rect.Width + cs.Offset + 20 + hWidth / 2;
            yc = rect.Y + rect.Height / 2;
            DrawLegend(g, xc, yc, hWidth, hHeight, ds, cs);
        }
예제 #4
0
        public ChartCanvas(CGRect rect) : base(rect)
        {
            ContentMode      = UIViewContentMode.Redraw;
            AutoresizingMask = UIViewAutoresizing.All;
            BackColor        = Color.Wheat;

            PlotPanel = new PlotPanel(rect);
            AddSubview(PlotPanel);

            // Subscribing to a paint eventhandler to drawingPanel:
            PlotPanel.Paint += PlotPanelPaint;

            // Subscribing to a paint eventhandler to drawingPanel:
            PlotPanel.Paint += PlotPanelPaint;

            cs = new ChartStyle(this);
            ds = new DataSeries();
            lg = new Legend(this);
            lg.IsLegendVisible = true;
        }
예제 #5
0
        public ChartCanvas(CGRect rect)
            : base(rect)
        {
            ContentMode = UIViewContentMode.Redraw;
            AutoresizingMask = UIViewAutoresizing.All;
            BackColor = Color.Wheat;

            PlotPanel = new PlotPanel (rect);
            AddSubview (PlotPanel);

            // Subscribing to a paint eventhandler to drawingPanel:
            PlotPanel.Paint += PlotPanelPaint;

            // Subscribing to a paint eventhandler to drawingPanel:
            PlotPanel.Paint += PlotPanelPaint;

            cs = new ChartStyle (this);
            ds = new DataSeries ();
            lg = new Legend (this);
            lg.IsLegendVisible = true;
        }
예제 #6
0
        public void AddLegend(Graphics g, DataSeries ds, ChartStyle cs)
        {
            if (ds.DataList.Count < 1)
            {
                return;
            }
            if (!IsLegendVisible)
            {
                return;
            }
            int numberOfDataValues = ds.DataList.Count;
            string[] legendLabels = new string[ds.LabelList.Count];
            for (int i = 0; i < ds.LabelList.Count;i++)
            {
                legendLabels[i] = (string)ds.LabelList[i];
            }
            // float offSet = 20;
            float xc = 0f;
            float yc = 0f;
            SizeF size = g.MeasureString(legendLabels[0], LegendFont);
            float legendWidth = size.Width;
            for (int i = 0; i < legendLabels.Length; i++)
            {
                size = g.MeasureString(legendLabels[i], LegendFont);
                float tempWidth = size.Width;
                if (legendWidth < tempWidth)
                    legendWidth = tempWidth;
            }
            legendWidth = legendWidth + 35.0f;
            float hWidth = legendWidth / 2;
            float legendHeight = 18.0f * numberOfDataValues;
            float hHeight = legendHeight / 2;

            Rectangle rect = cs.SetPieArea();
            xc = rect.X + rect.Width + cs.Offset + 20 + hWidth / 2;
            yc = rect.Y + rect.Height / 2;
            DrawLegend(g, xc, yc, hWidth, hHeight, ds, cs);
        }
예제 #7
0
        private void DrawLegend(Graphics g, float xCenter, float yCenter, 
            float hWidth, float hHeight, DataSeries ds, ChartStyle cs)
        {
            float spacing = 8.0f;
            float textHeight = 8.0f;
            float htextHeight = textHeight / 2.0f;
            float lineLength = 12.0f;
            float hlineLength = lineLength / 2.0f;
            Rectangle legendRectangle;
            Pen aPen = new Pen(LegendBorderColor, 1f);
            SolidBrush 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);
                }

                for (int i = 0; i < ds.DataList.Count; i++)
                {
                    float xSymbol = legendRectangle.X + spacing + hlineLength;
                    float xText = legendRectangle.X + 2 * spacing + lineLength;
                    float yText = legendRectangle.Y + (i + 1) * spacing +
                        (2 * i + 1) * htextHeight;
                    aPen = new Pen(ds.BorderColor, ds.BorderThickness);
                    Color fillColor = Color.FromArgb(ds.CMap[i, 0], ds.CMap[i, 1],
                                ds.CMap[i, 2], ds.CMap[i, 3]);
                    aBrush = new SolidBrush(fillColor);
                    // Draw symbols:
                    float hsize = 5f;
                    PointF[] pts = new PointF[4];
                    pts[0] = new PointF(xSymbol - hsize, yText - hsize);
                    pts[1] = new PointF(xSymbol + hsize, yText - hsize);
                    pts[2] = new PointF(xSymbol + hsize, yText + hsize);
                    pts[3] = new PointF(xSymbol - hsize, yText + hsize);
                    g.FillPolygon(aBrush, pts);
                    g.DrawPolygon(aPen, pts);
                    // Draw text:
                    StringFormat sFormat = new StringFormat();
                    sFormat.Alignment = StringAlignment.Near;
                    g.DrawString((string)ds.LabelList[i], LegendFont,
                        new SolidBrush(TextColor),
                        new PointF(xText, yText - 8), sFormat);
                }
            }
            aPen.Dispose();
            aBrush.Dispose();
        }
예제 #8
0
        public void AddPie(Graphics g, ChartStyle cs)
        {
            var aBrush = new SolidBrush (Color.Black);
            var aPen = new Pen(BorderColor);
            int nData = DataList.Count;
            float fSum = 0;
            for (int i = 0; i < nData; i++)
                fSum = fSum + (float)DataList[i];
            float startAngle = 0;
            float sweepAngle = 0;
            CGRect rect = cs.SetPieArea ();

            for (int i = 0; i < nData; i++) {
                Color fillColor = Color.FromArgb (CMap[i, 0], CMap[i, 1], CMap[i, 2], CMap[i, 3]);
                aBrush = new SolidBrush(fillColor);
                var explode = (int)ExplodeList[i];

                if (fSum < 1) {
                    startAngle = startAngle + sweepAngle;
                    sweepAngle = 360 * (float)DataList[i];
                } else if (fSum >= 1) {
                    startAngle = startAngle + sweepAngle;
                    sweepAngle = 360 * (float)DataList[i] / fSum;
                }

                var xshift = (int)(explode * Math.Cos((startAngle + sweepAngle / 2) * Math.PI / 180));
                var yshift = (int)(explode * Math.Sin((startAngle + sweepAngle / 2) * Math.PI / 180));
                var rect1 = new CGRect (rect.X + xshift, rect.Y + yshift, rect.Width, rect.Height);
                g.FillPie (aBrush, (Rectangle)rect1, startAngle, sweepAngle);
                g.DrawPie (aPen, (Rectangle)rect1, startAngle, sweepAngle);
            }
        }
예제 #9
0
        public void AddLegend(Graphics g, DataSeries ds, ChartStyle cs)
        {
            if (ds.DataList.Count < 1)
                return;
            if (!IsLegendVisible)
                return;
            int numberOfDataValues = ds.DataList.Count;
            string[] legendLabels = new string[ds.LabelList.Count];
            for (int i = 0; i < ds.LabelList.Count; i++)
                legendLabels[i] = (string)ds.LabelList[i];
            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 + 35f;
            float hWidth = legendWidth / 2;
            float legendHeight = 18f * numberOfDataValues;
            float hHeight = legendHeight / 2;

            CGRect rect = cs.SetPieArea ();
            xc = (float)(rect.X + rect.Width + cs.Offset + 20 + hWidth / 2);
            yc = (float)(rect.Y + rect.Height / 2);
            DrawLegend (g, xc, yc, hWidth, hHeight, ds, cs);
        }