コード例 #1
0
        public void AddLines(Graphics g, ChartStyle cs)
        {
            // Plot lines:
            foreach (DataSeries ds in DataSeriesList)
            {
                if (ds.LineStyle.IsVisible == true)
                {
                    Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness);
                    aPen.DashStyle = ds.LineStyle.Pattern;
                    if (ds.LineStyle.PlotMethod == LineStyle.PlotLinesMethodEnum.Lines)
                    {
                        for (int i = 1; i < ds.PointList.Count; i++)
                        {
                            g.DrawLine(aPen, cs.Point2D((PointF)ds.PointList[i - 1]),
                                       cs.Point2D((PointF)ds.PointList[i]));
                        }
                    }
                    else if (ds.LineStyle.PlotMethod == LineStyle.PlotLinesMethodEnum.Splines)
                    {
                        ArrayList al = new ArrayList();
                        for (int i = 0; i < ds.PointList.Count; i++)
                        {
                            PointF pt = (PointF)ds.PointList[i];
                            if (pt.X >= cs.XLimMin && pt.X <= cs.XLimMax &&
                                pt.Y >= cs.YLimMin && pt.Y <= cs.YLimMax)
                            {
                                al.Add(pt);
                            }
                        }
                        PointF[] pts = new PointF[al.Count];
                        for (int i = 0; i < pts.Length; i++)
                        {
                            pts[i] = cs.Point2D((PointF)(al[i]));
                        }
                        g.DrawCurve(aPen, pts);
                    }
                    aPen.Dispose();
                }
            }

            // Plot Symbols:
            foreach (DataSeries ds in DataSeriesList)
            {
                for (int i = 0; i < ds.PointList.Count; i++)
                {
                    PointF pt = (PointF)ds.PointList[i];
                    if (pt.X >= cs.XLimMin && pt.X <= cs.XLimMax &&
                        pt.Y >= cs.YLimMin && pt.Y <= cs.YLimMax)
                    {
                        ds.SymbolStyle.DrawSymbol(g, cs.Point2D((PointF)ds.PointList[i]));
                    }
                }
            }
        }
コード例 #2
0
        public void AddLines(Graphics g, ChartStyle cs)
        {
            // Plot lines:
            foreach (DataSeries ds in DataSeriesList)
            {
                if (ds.LineStyle.IsVisible == true)
                {
                    Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness);
                    aPen.DashStyle = ds.LineStyle.Pattern;
                    if (ds.LineStyle.PlotMethod == LineStyle.PlotLinesMethodEnum.Lines)
                    {
                        for (int i = 1; i < ds.PointList.Count; i++)
                        {
                            g.DrawLine(aPen, cs.Point2D((PointF)ds.PointList[i - 1]),
                                             cs.Point2D((PointF)ds.PointList[i]));
                        }
                    }
                    else if (ds.LineStyle.PlotMethod == LineStyle.PlotLinesMethodEnum.Splines)
                    {
                        ArrayList al = new ArrayList();
                        for (int i = 0; i < ds.PointList.Count; i++)
                        {
                            PointF pt = (PointF)ds.PointList[i];
                            if (pt.X >= cs.XLimMin && pt.X <= cs.XLimMax &&
                                pt.Y >= cs.YLimMin && pt.Y <= cs.YLimMax)
                            {
                                al.Add(pt);
                            }
                        }
                        PointF[] pts = new PointF[al.Count];
                        for (int i = 0; i < pts.Length; i++)
                        {
                            pts[i] = cs.Point2D((PointF)(al[i]));
                        }
                        g.DrawCurve(aPen, pts);
                    }
                    aPen.Dispose();
                }
            }

            // Plot Symbols:
            foreach (DataSeries ds in DataSeriesList)
            {
                for (int i = 0; i < ds.PointList.Count; i++)
                {
                    PointF pt = (PointF)ds.PointList[i];
                    if (pt.X >= cs.XLimMin && pt.X <= cs.XLimMax &&
                        pt.Y >= cs.YLimMin && pt.Y <= cs.YLimMax)
                    {
                        ds.SymbolStyle.DrawSymbol(g, cs.Point2D((PointF)ds.PointList[i]));
                    }
                }
            }
        }
コード例 #3
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);
                    ds.SymbolStyle.DrawSymbol(g, new PointF(xSymbol, yText));
                    // 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();
        }
コード例 #4
0
        public DrawingView(CGRect rect) : base(rect)
        {
            ContentMode      = UIViewContentMode.Redraw;
            AutoresizingMask = UIViewAutoresizing.All;
            BackColor        = Color.Wheat;
            cs         = new ChartStyle(this);
            cs.XLimMin = 0f;
            cs.XLimMax = 6f;
            cs.YLimMin = -1.5f;
            cs.YLimMax = 1.5f;
            cs.XTick   = 1f;
            cs.YTick   = .5f;
            cs.XLabel  = "This is X axis";
            cs.YLabel  = "This is Y axis";
            cs.Title   = "Sine and Cosine Chart";
            lg         = new Legend {
                IsLegendVisible = true
            };

            dc = new DataCollection();
        }
コード例 #5
0
        public DrawingView(CGRect rect)
            : base(rect)
        {
            ContentMode = UIViewContentMode.Redraw;
            AutoresizingMask = UIViewAutoresizing.All;
            BackColor = Color.Wheat;
            cs = new ChartStyle(this);
            cs.XLimMin = 0f;
            cs.XLimMax = 6f;
            cs.YLimMin = -1.5f;
            cs.YLimMax = 1.5f;
            cs.XTick = 1f;
            cs.YTick = .5f;
            cs.XLabel = "This is X axis";
            cs.YLabel = "This is Y axis";
            cs.Title = "Sine and Cosine Chart";
            lg = new Legend {
                IsLegendVisible = true
            };

            dc = new DataCollection ();
        }
コード例 #6
0
        public DrawingView(RectangleF rect) : base(rect)
        {
            ContentMode           = UIViewContentMode.Redraw;
            this.AutoresizingMask = UIViewAutoresizing.All;
            this.BackColor        = Color.Wheat;

            // Set Form1 size:
//			this.Width = 350;
//			this.Height = 300;
            dc                 = new DataCollection();
            cs                 = new ChartStyle(this);
            cs.XLimMin         = 0f;
            cs.XLimMax         = 6f;
            cs.YLimMin         = -1.5f;
            cs.YLimMax         = 1.5f;
            cs.XTick           = 1.0f;
            cs.YTick           = 0.5f;
            cs.XLabel          = "This is X axis";
            cs.YLabel          = "This is Y axis";
            cs.Title           = "Sine and Cosine Chart";
            lg                 = new Legend();
            lg.IsLegendVisible = true;
        }
コード例 #7
0
        public DrawingView(RectangleF rect)
            : base(rect)
        {
            ContentMode = UIViewContentMode.Redraw;
            this.AutoresizingMask = UIViewAutoresizing.All;
            this.BackColor = Color.Wheat;

            // Set Form1 size:
            //			this.Width = 350;
            //			this.Height = 300;
            dc = new DataCollection();
            cs = new ChartStyle(this);
            cs.XLimMin = 0f;
            cs.XLimMax = 6f;
            cs.YLimMin = -1.5f;
            cs.YLimMax = 1.5f;
            cs.XTick = 1.0f;
            cs.YTick = 0.5f;
            cs.XLabel = "This is X axis";
            cs.YLabel = "This is Y axis";
            cs.Title = "Sine and Cosine Chart";
            lg = new Legend();
            lg.IsLegendVisible = true;
        }
コード例 #8
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);
        }
コード例 #9
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);
                    ds.SymbolStyle.DrawSymbol(g, new PointF(xSymbol, yText));
                    // 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();
        }
コード例 #10
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;

            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);
        }