public void AddStairstep(ChartStyleGridlines csg)
        {
            foreach (DataSeriesStairstep ds in DataList)
            {
                List <Point> ptList = new List <Point>();
                Point[]      pts    = new Point[2];
                ds.AddStairstepLinePattern();

                // Create Stairstep data:
                for (int i = 0; i < ds.LineSeries.Points.Count - 1; i++)
                {
                    pts[0] = ds.LineSeries.Points[i];
                    pts[1] = ds.LineSeries.Points[i + 1];
                    ptList.Add(pts[0]);
                    ptList.Add(new Point(pts[1].X, pts[0].Y));
                }
                ptList.Add(new Point(pts[1].X, pts[0].Y));

                // Draw stairstep line:
                for (int i = 0; i < ptList.Count; i++)
                {
                    ds.StairstepLineSeries.Points.Add(csg.NormalizePoint(ptList[i]));
                }
                csg.ChartCanvas.Children.Add(ds.StairstepLineSeries);
            }
        }
        public void AddAreas(ChartStyleGridlines csg)
        {
            int nSeries = AreaList.Count;
            int nPoints = AreaList[0].AreaSeries.Points.Count;

            double[] ySum = new double[nPoints];
            Point[]  pts  = new Point[2 * nPoints];
            Point[]  pt0  = new Point[nPoints];
            Point[]  pt1  = new Point[nPoints];

            for (int i = 0; i < nPoints; i++)
            {
                ySum[i] = AreaAxis;
            }

            foreach (DataSeriesArea area in AreaList)
            {
                area.AddBorderPattern();
                for (int i = 0; i < nPoints; i++)
                {
                    pt0[i]   = new Point(area.AreaSeries.Points[i].X, ySum[i]);
                    ySum[i] += area.AreaSeries.Points[i].Y;
                    pt1[i]   = new Point(area.AreaSeries.Points[i].X, ySum[i]);
                    pts[i]   = csg.NormalizePoint(pt0[i]);
                    pts[2 * nPoints - 1 - i] = csg.NormalizePoint(pt1[i]);
                }

                area.AreaSeries.Points.Clear();
                for (int i = 0; i < pts.GetLength(0); i++)
                {
                    area.AreaSeries.Points.Add(pts[i]);
                }
                csg.ChartCanvas.Children.Add(area.AreaSeries);
            }
        }
示例#3
0
        private void AddChart()
        {
            cs   = new ChartStyleGridlines();
            dc   = new DataCollectionArea();
            area = new DataSeriesArea();

            cs.ChartCanvas     = chartCanvas;
            cs.TextCanvas      = textCanvas;
            cs.Title           = "Area Chart";
            cs.Xmin            = 0;
            cs.Xmax            = 10;
            cs.Ymin            = 0;
            cs.Ymax            = 10;
            cs.XTick           = 2;
            cs.YTick           = 2;
            cs.GridlinePattern = ChartStyleGridlines.GridlinePatternEnum.Dot;
            cs.GridlineColor   = Brushes.Black;
            cs.AddChartStyle(tbTitle, tbXLabel, tbYLabel);
            dc.AreaList.Clear();

            // Add sine data:
            area             = new DataSeriesArea();
            area.BorderColor = Brushes.Black;
            area.FillColor   = Brushes.LightPink;
            for (int i = 0; i < 41; i++)
            {
                area.AreaSeries.Points.Add(new Point(0.25 * i, 2.0 + Math.Sin(0.25 * i)));
            }
            dc.AreaList.Add(area);

            // Add cosine data:
            area             = new DataSeriesArea();
            area.BorderColor = Brushes.Black;
            area.FillColor   = Brushes.LightBlue;
            for (int i = 0; i < 41; i++)
            {
                area.AreaSeries.Points.Add(new Point(0.25 * i, 2.0 + Math.Cos(0.25 * i)));
            }
            dc.AreaList.Add(area);

            // Add another sine data:
            area             = new DataSeriesArea();
            area.BorderColor = Brushes.Black;
            area.FillColor   = Brushes.LightGreen;
            for (int i = 0; i < 41; i++)
            {
                area.AreaSeries.Points.Add(new Point(0.25 * i, 3.0 + Math.Sin(0.25 * i)));
            }
            dc.AreaList.Add(area);
            dc.AddAreas(cs);
        }
        private void DrawHorizontalBar(Point pt, ChartStyleGridlines csg, DataSeriesBar ds, double width, double x)
        {
            Polygon plg = new Polygon();

            plg.Fill            = ds.FillColor;
            plg.Stroke          = ds.BorderColor;
            plg.StrokeThickness = ds.BorderThickness;

            double y = pt.Y - 0.5 * csg.YTick;

            plg.Points.Add(csg.NormalizePoint(new Point(x, y - width / 2)));
            plg.Points.Add(csg.NormalizePoint(new Point(x, y + width / 2)));
            plg.Points.Add(csg.NormalizePoint(new Point(x + pt.X, y + width / 2)));
            plg.Points.Add(csg.NormalizePoint(new Point(x + pt.X, y - width / 2)));
            csg.ChartCanvas.Children.Add(plg);
        }
        private void DrawVerticalBar(Point pt, ChartStyleGridlines csg, DataSeriesBar ds, double width, double y)
        {
            Polygon plg = new Polygon();

            plg.Fill            = ds.FillColor;
            plg.Stroke          = ds.BorderColor;
            plg.StrokeThickness = ds.BorderThickness;

            double x = pt.X - 0.5 * csg.XTick;

            plg.Points.Add(csg.NormalizePoint(new Point(x - width / 2, y)));
            plg.Points.Add(csg.NormalizePoint(new Point(x + width / 2, y)));
            plg.Points.Add(csg.NormalizePoint(new Point(x + width / 2, y + pt.Y)));
            plg.Points.Add(csg.NormalizePoint(new Point(x - width / 2, y + pt.Y)));
            csg.ChartCanvas.Children.Add(plg);
        }
        public void AddErrorbars(ChartStyleGridlines csg)
        {
            Line line;

            foreach (DataSeriesErrorbar ds in DataList)
            {
                double barLength = (csg.NormalizePoint(ds.LineSeries.Points[1]).X -
                                    csg.NormalizePoint(ds.LineSeries.Points[0]).X) / 3;

                for (int i = 0; i < ds.ErrorLineSeries.Points.Count; i++)
                {
                    Point   ep  = ds.ErrorLineSeries.Points[i];
                    Point   dp  = ds.LineSeries.Points[i];
                    Point[] pts = new Point[2];
                    pts[0]               = csg.NormalizePoint(new Point(dp.X, dp.Y - ep.Y / 2));
                    pts[1]               = csg.NormalizePoint(new Point(dp.X, dp.Y + ep.Y / 2));
                    line                 = new Line();
                    line.Stroke          = ds.ErrorLineColor;
                    line.StrokeThickness = ds.ErrorLineThickness;
                    ds.AddErrorLinePattern();
                    line.X1 = pts[0].X;
                    line.Y1 = pts[0].Y;
                    line.X2 = pts[1].X;
                    line.Y2 = pts[1].Y;
                    csg.ChartCanvas.Children.Add(line);
                    line                 = new Line();
                    line.Stroke          = ds.ErrorLineColor;
                    line.StrokeThickness = ds.ErrorLineThickness;
                    ds.AddErrorLinePattern();
                    line.X1 = pts[0].X - barLength / 2;
                    line.Y1 = pts[0].Y;
                    line.X2 = pts[0].X + barLength / 2;
                    line.Y2 = pts[0].Y;
                    csg.ChartCanvas.Children.Add(line);
                    line                 = new Line();
                    line.Stroke          = ds.ErrorLineColor;
                    line.StrokeThickness = ds.ErrorLineThickness;
                    ds.AddErrorLinePattern();
                    line.X1 = pts[1].X - barLength / 2;
                    line.Y1 = pts[1].Y;
                    line.X2 = pts[1].X + barLength / 2;
                    line.Y2 = pts[1].Y;
                    csg.ChartCanvas.Children.Add(line);
                }
            }
        }
        private void AddVerticalBarChart()
        {
            cs = new ChartStyleGridlines();
            dc = new DataCollectionBar();
            ds = new DataSeriesBar();

            dc.BarType         = DataCollectionBar.BarTypeEnum.Vertical;
            cs.ChartCanvas     = chartCanvas;
            cs.TextCanvas      = textCanvas;
            cs.Title           = "Bar Chart";
            cs.Xmin            = 0;
            cs.Xmax            = 5;
            cs.Ymin            = 0;
            cs.Ymax            = 10;
            cs.XTick           = 1;
            cs.YTick           = 2;
            cs.GridlinePattern = ChartStyleGridlines.GridlinePatternEnum.Dot;
            cs.GridlineColor   = Brushes.Black;
            cs.AddChartStyle(tbTitle, tbXLabel, tbYLabel);

            // Draw the bar chart:
            dc.DataList.Clear();
            ds             = new DataSeriesBar();
            ds.BorderColor = Brushes.Red;
            ds.FillColor   = Brushes.Green;
            ds.BarWidth    = 0.6;

            /*for (int i = 0; i < 5; i++)
             * {
             *  double x = i + 1.0;
             *  double y = 2.0 * x;
             *  ds.LineSeries.Points.Add(new Point(x, y));
             * }*/

            double[] x = new double[] { 1, 2, 3, 4, 5 };
            double[] y = new double[] { 2, 0, 3, 8, 10 };
            for (int i = 0; i < x.Length; i++)
            {
                ds.LineSeries.Points.Add(new Point(x[i], y[i]));
            }

            dc.DataList.Add(ds);
            dc.AddBars(cs);
        }
        private void DrawHorizontalBar1(Point pt, ChartStyleGridlines csg, DataSeriesBar ds, int nSeries, int n)
        {
            Polygon plg = new Polygon();

            plg.Fill            = ds.FillColor;
            plg.Stroke          = ds.BorderColor;
            plg.StrokeThickness = ds.BorderThickness;

            double width = 0.7 * csg.YTick;
            double w1    = width / nSeries;
            double w     = ds.BarWidth * w1;
            double space = (w1 - w) / 2;
            double y     = pt.Y - 0.5 * csg.YTick;

            plg.Points.Add(csg.NormalizePoint(new Point(0, y - width / 2 + space + n * w1)));
            plg.Points.Add(csg.NormalizePoint(new Point(0, y - width / 2 + space + n * w1 + w)));
            plg.Points.Add(csg.NormalizePoint(new Point(pt.X, y - width / 2 + space + n * w1 + w)));
            plg.Points.Add(csg.NormalizePoint(new Point(pt.X, y - width / 2 + space + n * w1)));
            csg.ChartCanvas.Children.Add(plg);
        }
        public void AddStems(ChartStyleGridlines csg)
        {
            foreach (DataSeries ds in DataList)
            {
                Point[] pts = new Point[2];
                for (int i = 0; i < ds.LineSeries.Points.Count; i++)
                {
                    pts[0] = csg.NormalizePoint(new Point(ds.LineSeries.Points[i].X, 0));
                    pts[1] = csg.NormalizePoint(ds.LineSeries.Points[i]);

                    Line line = new Line();
                    line.Stroke          = ds.LineColor;
                    line.StrokeThickness = ds.LineThickness;
                    line.X1 = pts[0].X;
                    line.Y1 = pts[0].Y;
                    line.X2 = pts[1].X;
                    line.Y2 = pts[1].Y;
                    csg.ChartCanvas.Children.Add(line);
                    ds.Symbols.AddSymbol(csg.ChartCanvas, csg.NormalizePoint(ds.LineSeries.Points[i]));
                }
            }
        }
        private void AddChart()
        {
            cs = new ChartStyleGridlines();
            dc = new DataCollectionStem();
            ds = new DataSeries();

            cs.ChartCanvas     = chartCanvas;
            cs.TextCanvas      = textCanvas;
            cs.Title           = "Stem Chart";
            cs.Xmin            = 0;
            cs.Xmax            = 8;
            cs.Ymin            = -1.5;
            cs.Ymax            = 1.5;
            cs.XTick           = 1;
            cs.YTick           = 0.5;
            cs.GridlinePattern = ChartStyleGridlines.GridlinePatternEnum.Dot;
            cs.GridlineColor   = Brushes.Black;
            cs.AddChartStyle(tbTitle, tbXLabel, tbYLabel);

            // Draw the stair step chart:
            dc.DataList.Clear();
            ds = new DataSeries();

            for (int i = 0; i < 50; i++)
            {
                ds.LineSeries.Points.Add(new Point(0.4 * i, Math.Sin(0.4 * i)));
            }

            ds.LineColor           = Brushes.Red;
            ds.Symbols.SymbolType  = Symbols.SymbolTypeEnum.Diamond;
            ds.Symbols.FillColor   = Brushes.Yellow;
            ds.Symbols.BorderColor = Brushes.DarkGreen;


            dc.DataList.Add(ds);
            dc.AddStems(cs);
        }
示例#11
0
        private void AddChart()
        {
            cs = new ChartStyleGridlines();
            dc = new DataCollectionErrorbar();
            ds = new DataSeriesErrorbar();

            cs.ChartCanvas     = chartCanvas;
            cs.TextCanvas      = textCanvas;
            cs.Title           = "Error Bar Chart";
            cs.Xmin            = 0;
            cs.Xmax            = 12;
            cs.Ymin            = -1;
            cs.Ymax            = 6;
            cs.XTick           = 2;
            cs.YTick           = 1;
            cs.GridlinePattern = ChartStyleGridlines.GridlinePatternEnum.Dot;
            cs.GridlineColor   = Brushes.Black;
            cs.AddChartStyle(tbTitle, tbXLabel, tbYLabel);

            dc.DataList.Clear();
            dc.ErrorList.Clear();
            ds                     = new DataSeriesErrorbar();
            ds.LineColor           = Brushes.Blue;
            ds.Symbols.SymbolType  = Symbols.SymbolTypeEnum.Circle;
            ds.Symbols.BorderColor = Brushes.DarkGreen;
            ds.ErrorLineColor      = Brushes.Red;

            for (int i = 2; i < 22; i++)
            {
                ds.LineSeries.Points.Add(new Point(0.5 * i, 10.0 * Math.Exp(-0.5 * i)));
                ds.ErrorLineSeries.Points.Add(new Point(0.5 * i, 3.0 / (0.5 * i)));
            }
            dc.DataList.Add(ds);
            dc.AddErrorbars(cs);
            dc.AddLines(cs);
        }
        private void AddHorizontalBarChart()
        {
            cs = new ChartStyleGridlines();
            dc = new DataCollectionBar();
            ds = new DataSeriesBar();

            dc.BarType         = DataCollectionBar.BarTypeEnum.Horizontal;
            cs.ChartCanvas     = chartCanvas;
            cs.TextCanvas      = textCanvas;
            cs.Title           = "Bar Chart";
            cs.Xmin            = 0;
            cs.Xmax            = 10;
            cs.Ymin            = 0;
            cs.Ymax            = 5;
            cs.XTick           = 2;
            cs.YTick           = 1;
            cs.GridlinePattern = ChartStyleGridlines.GridlinePatternEnum.Dot;
            cs.GridlineColor   = Brushes.Black;
            cs.AddChartStyle(tbTitle, tbXLabel, tbYLabel);

            // Draw the bar chart:
            dc.DataList.Clear();
            ds             = new DataSeriesBar();
            ds.BorderColor = Brushes.Red;
            ds.FillColor   = Brushes.Green;
            ds.BarWidth    = 0.6;

            for (int i = 0; i < 5; i++)
            {
                double x = i + 1.0;
                double y = 2.0 * x;
                ds.LineSeries.Points.Add(new Point(y, x));
            }
            dc.DataList.Add(ds);
            dc.AddBars(cs);
        }
        public void AddBars(ChartStyleGridlines csg)
        {
            int    nSeries = DataList.Count;
            double width;

            switch (BarType)
            {
            case BarTypeEnum.Vertical:
                if (nSeries == 1)
                {
                    foreach (DataSeriesBar ds in DataList)
                    {
                        width = csg.XTick * ds.BarWidth;
                        for (int i = 0; i < ds.LineSeries.Points.Count; i++)
                        {
                            DrawVerticalBar(ds.LineSeries.Points[i], csg, ds, width, 0);
                        }
                    }
                }
                else
                {
                    int j = 0;
                    foreach (DataSeriesBar ds in DataList)
                    {
                        for (int i = 0; i < ds.LineSeries.Points.Count; i++)
                        {
                            DrawVerticalBar1(ds.LineSeries.Points[i], csg, ds, nSeries, j);
                        }
                        j++;
                    }
                }
                break;

            case BarTypeEnum.VerticalOverlay:
                if (nSeries > 1)
                {
                    int j = 0;
                    foreach (DataSeriesBar ds in DataList)
                    {
                        width = csg.XTick * ds.BarWidth;
                        width = width / Math.Pow(2, j);
                        for (int i = 0; i < ds.LineSeries.Points.Count; i++)
                        {
                            DrawVerticalBar(ds.LineSeries.Points[i], csg, ds, width, 0);
                        }
                        j++;
                    }
                }
                break;

            case BarTypeEnum.VerticalStack:
                if (nSeries > 1)
                {
                    List <Point> temp  = new List <Point>();
                    double[]     tempy = new double[DataList[0].LineSeries.Points.Count];

                    foreach (DataSeriesBar ds in DataList)
                    {
                        width = csg.XTick * ds.BarWidth;

                        for (int i = 0; i < ds.LineSeries.Points.Count; i++)
                        {
                            if (temp.Count > 0)
                            {
                                tempy[i] += temp[i].Y;
                            }
                            DrawVerticalBar(ds.LineSeries.Points[i], csg, ds, width, tempy[i]);
                        }
                        temp.Clear();
                        temp.AddRange(ds.LineSeries.Points);
                    }
                }
                break;

            case BarTypeEnum.Horizontal:
                if (nSeries == 1)
                {
                    foreach (DataSeriesBar ds in DataList)
                    {
                        width = csg.YTick * ds.BarWidth;
                        for (int i = 0; i < ds.LineSeries.Points.Count; i++)
                        {
                            DrawHorizontalBar(ds.LineSeries.Points[i], csg, ds, width, 0);
                        }
                    }
                }
                else
                {
                    int j = 0;
                    foreach (DataSeriesBar ds in DataList)
                    {
                        for (int i = 0; i < ds.LineSeries.Points.Count; i++)
                        {
                            DrawHorizontalBar1(ds.LineSeries.Points[i], csg, ds, nSeries, j);
                        }
                        j++;
                    }
                }
                break;

            case BarTypeEnum.HorizontalOverlay:
                if (nSeries > 1)
                {
                    int j = 0;
                    foreach (DataSeriesBar ds in DataList)
                    {
                        width = csg.YTick * ds.BarWidth;
                        width = width / Math.Pow(2, j);
                        for (int i = 0; i < ds.LineSeries.Points.Count; i++)
                        {
                            DrawHorizontalBar(ds.LineSeries.Points[i], csg, ds, width, 0);
                        }
                        j++;
                    }
                }
                break;

            case BarTypeEnum.HorizontalStack:
                if (nSeries > 1)
                {
                    List <Point> temp  = new List <Point>();
                    double[]     tempy = new double[DataList[0].LineSeries.Points.Count];

                    foreach (DataSeriesBar ds in DataList)
                    {
                        width = csg.YTick * ds.BarWidth;

                        for (int i = 0; i < ds.LineSeries.Points.Count; i++)
                        {
                            if (temp.Count > 0)
                            {
                                tempy[i] += temp[i].X;
                            }
                            DrawHorizontalBar(ds.LineSeries.Points[i], csg, ds, width, tempy[i]);
                        }
                        temp.Clear();
                        temp.AddRange(ds.LineSeries.Points);
                    }
                }
                break;
            }
        }
        private void AddVerticalGroupBarChart()
        {
            cs = new ChartStyleGridlines();
            dc = new DataCollectionBar();
            ds = new DataSeriesBar();

            dc.BarType         = DataCollectionBar.BarTypeEnum.VerticalStack;
            cs.ChartCanvas     = chartCanvas;
            cs.TextCanvas      = textCanvas;
            cs.Title           = dc.BarType.ToString();
            cs.Xmin            = 0;
            cs.Xmax            = 5;
            cs.Ymin            = 0;
            cs.Ymax            = 25;
            cs.XTick           = 1;
            cs.YTick           = 5;
            cs.GridlinePattern = ChartStyleGridlines.GridlinePatternEnum.Dot;
            cs.GridlineColor   = Brushes.Black;
            cs.AddChartStyle(tbTitle, tbXLabel, tbYLabel);

            // Add the first bar series:
            dc.DataList.Clear();
            ds             = new DataSeriesBar();
            ds.BorderColor = Brushes.Red;
            ds.FillColor   = Brushes.Green;
            ds.BarWidth    = 0.8;

            for (int i = 0; i < 5; i++)
            {
                double x = i + 1.0;
                double y = 2.0 * x;
                ds.LineSeries.Points.Add(new Point(x, y));
            }
            dc.DataList.Add(ds);

            // Add the second bar series:
            ds             = new DataSeriesBar();
            ds.BorderColor = Brushes.Red;
            ds.FillColor   = Brushes.Yellow;
            ds.BarWidth    = 0.8;

            for (int i = 0; i < 5; i++)
            {
                double x = i + 1.0;
                double y = 1.5 * x;
                ds.LineSeries.Points.Add(new Point(x, y));
            }
            dc.DataList.Add(ds);

            // Add the third bar series:
            ds             = new DataSeriesBar();
            ds.BorderColor = Brushes.Red;
            ds.FillColor   = Brushes.Blue;
            ds.BarWidth    = 0.8;

            for (int i = 0; i < 5; i++)
            {
                double x = i + 1.0;
                double y = 1.0 * x;
                ds.LineSeries.Points.Add(new Point(x, y));
            }
            dc.DataList.Add(ds);
            dc.AddBars(cs);
        }