Example #1
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;
            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 + 50.0f;
            float hWidth       = legendWidth / 2;
            float legendHeight = 18.0f * numberOfDataSeries;
            float hHeight      = legendHeight / 2;

            Rectangle rect = cs.SetPolarArea();

            xc = rect.X + rect.Width + cs.Offset + 15 + hWidth / 2;
            yc = rect.Y + rect.Height / 2;

            DrawLegend(g, xc, yc, hWidth, hHeight, dc, cs);
        }
Example #2
0
        private void DrawLegend(Graphics g, float xCenter, float yCenter,
                                float hWidth, float hHeight, DataCollection dc, ChartStyle cs)
        {
            float      spacing     = 8.0f;
            float      textHeight  = 8.0f;
            float      htextHeight = textHeight / 2.0f;
            float      lineLength  = 30.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);
                }

                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;
                    PointF ptStart = new PointF(legendRectangle.X + spacing, yText);
                    PointF ptEnd   = new PointF(legendRectangle.X + spacing + lineLength, yText);

                    g.DrawLine(aPen, ptStart, ptEnd);
                    // Draw text:
                    StringFormat sFormat = new StringFormat();
                    sFormat.Alignment = StringAlignment.Near;
                    g.DrawString(ds.SeriesName, LegendFont, new SolidBrush(textColor),
                                 new PointF(xText, yText - 8), sFormat);
                    n++;
                }
            }
            aPen.Dispose();
            aBrush.Dispose();
        }
        public void AddPolar(Graphics g, ChartStyle cs)
        {
            Rectangle rect = cs.SetPolarArea();
            float     xc   = rect.X + rect.Width / 2;
            float     yc   = rect.Y + rect.Height / 2;

            // Plot lines:
            foreach (DataSeries ds in DataSeriesList)
            {
                Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness);
                aPen.DashStyle = ds.LineStyle.Pattern;
                float r     = ((PointF)ds.PointList [0]).Y;
                float theta = ((PointF)ds.PointList [0]).X;
                float x     = cs.RNorm(r) * (float)Math.Cos(theta * Math.PI / 180) + xc;
                float y     = cs.RNorm(r) * (float)Math.Sin(theta * Math.PI / 180) + yc;

                if (ds.LineStyle.IsVisible == true)
                {
                    PointF ptStart = new PointF(x, y);
                    PointF ptEnd   = new PointF(x, y);
                    for (int i = 1; i < ds.PointList.Count; i++)
                    {
                        r     = ((PointF)ds.PointList [i - 1]).Y;
                        theta = ((PointF)ds.PointList [i - 1]).X;
                        if (cs.AngleDirection == ChartStyle.AngleDirectionEnum.CounterClockWise)
                        {
                            theta = -theta;
                        }
                        x       = cs.RNorm(r) * (float)Math.Cos(theta * Math.PI / 180) + xc;
                        y       = cs.RNorm(r) * (float)Math.Sin(theta * Math.PI / 180) + yc;
                        ptStart = new PointF(x, y);
                        r       = ((PointF)ds.PointList [i]).Y;
                        theta   = ((PointF)ds.PointList [i]).X;
                        if (cs.AngleDirection == ChartStyle.AngleDirectionEnum.CounterClockWise)
                        {
                            theta = -theta;
                        }
                        x     = cs.RNorm(r) * (float)Math.Cos(theta * Math.PI / 180) + xc;
                        y     = cs.RNorm(r) * (float)Math.Sin(theta * Math.PI / 180) + yc;
                        ptEnd = new PointF(x, y);
                        g.DrawLine(aPen, ptStart, ptEnd);
                    }
                }
                aPen.Dispose();
            }
        }
        public void AddPolar(Graphics g, ChartStyle cs)
        {
            Rectangle rect = cs.SetPolarArea ();
            float xc = rect.X + rect.Width / 2;
            float yc = rect.Y + rect.Height / 2;
            // Plot lines:
            foreach (DataSeries ds in DataSeriesList) {
                Pen aPen = new Pen (ds.LineStyle.LineColor, ds.LineStyle.Thickness);
                aPen.DashStyle = ds.LineStyle.Pattern;
                float r = ((PointF)ds.PointList [0]).Y;
                float theta = ((PointF)ds.PointList [0]).X;
                float x = cs.RNorm (r) * (float)Math.Cos (theta * Math.PI / 180) + xc;
                float y = cs.RNorm (r) * (float)Math.Sin (theta * Math.PI / 180) + yc;

                if (ds.LineStyle.IsVisible == true) {
                    PointF ptStart = new PointF (x, y);
                    PointF ptEnd = new PointF (x, y);
                    for (int i = 1; i < ds.PointList.Count; i++) {
                        r = ((PointF)ds.PointList [i - 1]).Y;
                        theta = ((PointF)ds.PointList [i - 1]).X;
                        if (cs.AngleDirection == ChartStyle.AngleDirectionEnum.CounterClockWise) {
                            theta = -theta;
                        }
                        x = cs.RNorm (r) * (float)Math.Cos (theta * Math.PI / 180) + xc;
                        y = cs.RNorm (r) * (float)Math.Sin (theta * Math.PI / 180) + yc;
                        ptStart = new PointF (x, y);
                        r = ((PointF)ds.PointList [i]).Y;
                        theta = ((PointF)ds.PointList [i]).X;
                        if (cs.AngleDirection == ChartStyle.AngleDirectionEnum.CounterClockWise) {
                            theta = -theta;
                        }
                        x = cs.RNorm (r) * (float)Math.Cos (theta * Math.PI / 180) + xc;
                        y = cs.RNorm (r) * (float)Math.Sin (theta * Math.PI / 180) + yc;
                        ptEnd = new PointF (x, y);
                        g.DrawLine (aPen, ptStart, ptEnd);
                    }
                }
                aPen.Dispose ();
            }
        }
Example #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;
            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 + 50.0f;
            float hWidth = legendWidth / 2;
            float legendHeight = 18.0f * numberOfDataSeries;
            float hHeight = legendHeight / 2;

            Rectangle rect = cs.SetPolarArea ();
            xc = rect.X + rect.Width + cs.Offset + 15 + hWidth / 2;
            yc = rect.Y + rect.Height / 2;

            DrawLegend (g, xc, yc, hWidth, hHeight, dc, cs);
        }
        // Shared initialization code
        void Initialize()
        {
            this.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable;
            BackColor             = Color.Wheat;
            PlotPanel             = new PlotPanel(Frame);

            this.AddSubview(PlotPanel);

            // Subscribing to a paint eventhandler to drawingPanel:
            PlotPanel.Paint +=
                new PaintEventHandler(PlotPanelPaint);

            dc = new DataCollection();
            cs = new ChartStyle(this);
//			cs.RMax = 0.5f;
//			cs.RMin = 0f;
            cs.RMax           = 1f;
            cs.RMin           = -5f;
            cs.NTicks         = 4;
            cs.AngleStep      = 30;
            cs.AngleDirection = ChartStyle.AngleDirectionEnum.CounterClockWise;
            lg = new Legend();
            lg.IsLegendVisible = true;
        }
        // Shared initialization code
        void Initialize()
        {
            this.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable;
            BackColor = Color.Wheat;
            PlotPanel = new PlotPanel (Frame);

            this.AddSubview (PlotPanel);

            // Subscribing to a paint eventhandler to drawingPanel:
            PlotPanel.Paint +=
                new PaintEventHandler (PlotPanelPaint);

            dc = new DataCollection ();
            cs = new ChartStyle (this);
            //			cs.RMax = 0.5f;
            //			cs.RMin = 0f;
            cs.RMax = 1f;
            cs.RMin = -5f;
            cs.NTicks = 4;
            cs.AngleStep = 30;
            cs.AngleDirection = ChartStyle.AngleDirectionEnum.CounterClockWise;
            lg = new Legend ();
            lg.IsLegendVisible = true;
        }
Example #8
0
        private void DrawLegend(Graphics g, float xCenter, float yCenter, 
            float hWidth, float hHeight, DataCollection dc, ChartStyle cs)
        {
            float spacing = 8.0f;
            float textHeight = 8.0f;
            float htextHeight = textHeight / 2.0f;
            float lineLength = 30.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);
                }

                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;
                    PointF ptStart = new PointF (legendRectangle.X + spacing, yText);
                    PointF ptEnd = new PointF (legendRectangle.X + spacing + lineLength, yText);

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