Ejemplo n.º 1
0
        private void LineButton_Click(object sender, EventArgs e)
        {
            // generate some random Y data
            int pointCount = 10_000;

            double[] ys1 = RandomWalk(pointCount);
            double[] ys2 = RandomWalk(pointCount);
            double[] ys3 = RandomWalk(pointCount);

            // create a line plot containing the data
            var linePlot1 = new NPlot.LinePlot {
                DataSource = ys1, Color = Color.Red
            };
            var linePlot2 = new NPlot.LinePlot {
                DataSource = ys2, Color = Color.Green
            };
            var linePlot3 = new NPlot.LinePlot {
                DataSource = ys3, Color = Color.Blue
            };

            // add the line plot to the plot surface (user control)
            plotSurface2D1.Clear();
            plotSurface2D1.Add(linePlot1);
            plotSurface2D1.Add(linePlot2);
            plotSurface2D1.Add(linePlot3);
            plotSurface2D1.Title        = $"Line Plot ({pointCount:n0} points each)";
            plotSurface2D1.YAxis1.Label = "Vertical Axis Label";
            plotSurface2D1.XAxis1.Label = "Horizontal Axis Label";
            plotSurface2D1.Refresh();

            // allow the plot to be mouse-interactive
            plotSurface2D1.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag());
            plotSurface2D1.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag());
            plotSurface2D1.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(true));
        }
Ejemplo n.º 2
0
        public Image drawChart(List <int> xTime, List <double> yVel)
        {
            Bitmap bm = new Bitmap(PanelSize.Width, PanelSize.Height);

            using (Graphics g = Graphics.FromImage(bm)) {
                NPlot.Bitmap.PlotSurface2D plotSurface = new NPlot.Bitmap.PlotSurface2D(bm);

                NPlot.LinePlot linePlot = new NPlot.LinePlot(yVel, xTime);
                linePlot.Color = Color.Green;

                plotSurface.Add(linePlot);

                NPlot.Legend legende = new NPlot.Legend();

                NPlot.Grid grid = new NPlot.Grid();

                grid.HorizontalGridType = NPlot.Grid.GridType.Coarse;
                grid.VerticalGridType   = NPlot.Grid.GridType.Fine;
                plotSurface.Add(grid);


                Rectangle rectBounds = new Rectangle(0, 0, PanelSize.Width, PanelSize.Height);
                plotSurface.Draw(g, rectBounds);
            }

            return(bm);
        }
Ejemplo n.º 3
0
        public Image drawChart(List <long> xTime, List <double> yVel)
        {
            Bitmap bm = new Bitmap(PanelSize.Width, PanelSize.Height);

            using (Graphics g = Graphics.FromImage(bm)) {
                NPlot.Bitmap.PlotSurface2D plotSurface = new NPlot.Bitmap.PlotSurface2D(bm);
                plotSurface.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                NPlot.LinePlot linePlot = new NPlot.LinePlot(yVel, xTime);
                linePlot.Color = Color.Red;

                plotSurface.Add(linePlot);

                plotSurface.YAxis1.AutoScaleTicks = Autozoom;
                if (!Autozoom)
                {
                    plotSurface.YAxis1.WorldMax = YMax;
                    plotSurface.YAxis1.WorldMin = YMin;
                }

                plotSurface.Title        = Title;
                plotSurface.XAxis1.Label = XLabel;
                plotSurface.YAxis1.Label = YLabel;

                NPlot.Legend legende = new NPlot.Legend();

                NPlot.Grid grid = new NPlot.Grid();

                grid.HorizontalGridType = NPlot.Grid.GridType.Fine;
                grid.VerticalGridType   = NPlot.Grid.GridType.Fine;
                plotSurface.Add(grid);


                Rectangle rectBounds = new Rectangle(0, 0, PanelSize.Width, PanelSize.Height);
                plotSurface.Draw(g, rectBounds);
            }

            return(bm);
        }
Ejemplo n.º 4
0
        // Zu plotende Funktionen definieren

        public void AddLinePlot(
            IEnumerable <TX> xSeries,
            XAxisPosition xpos,
            IEnumerable <TY> ySeries,
            YAxisPosition ypos,
            Color _color,
            string Label,
            bool ShowLabelInLegend)
        {
            NPlot.LinePlot plot = new NPlot.LinePlot(ySeries, xSeries);

            plot.ShowInLegend = ShowLabelInLegend;
            plot.Label        = Label;
            plot.Color        = _color;

            MyPlot my = new MyPlot();

            my.plot          = plot;
            my.XAxisPosition = xpos == XAxisPosition.Bottom ? NPlot.PlotSurface2D.XAxisPosition.Bottom : NPlot.PlotSurface2D.XAxisPosition.Top;
            my.YAxisPosition = ypos == YAxisPosition.Left ? NPlot.PlotSurface2D.YAxisPosition.Left : NPlot.PlotSurface2D.YAxisPosition.Right;

            plots.Add(my);
        }
Ejemplo n.º 5
0
        internal static void ToDraw(int[] time, double[] valEntry, double[] valAlgo, TypeAction ta, TypeMeasure tm)
        {
            _npSurface.Clear();
            _npSurface.Title     = $"{tm} : {ta}";
            _npSurface.BackColor = Color.White;

            NPlot.Grid grid = new NPlot.Grid();
            _npSurface.Add(grid, NPlot.PlotSurface2D.XAxisPosition.Bottom,
                           NPlot.PlotSurface2D.YAxisPosition.Left);

            if (tm == TypeMeasure.Distance)
            {
                NPlot.LinePlot plot = new NPlot.LinePlot();

                plot.AbscissaData = time;
                plot.DataSource   = valAlgo;
                plot.Label        = "Algorithm";
                plot.Color        = Color.Blue;

                _npSurface.Add(plot, NPlot.PlotSurface2D.XAxisPosition.Bottom,
                               NPlot.PlotSurface2D.YAxisPosition.Left);
            }
            else
            {
                NPlot.LinePlot plotAlgo  = new NPlot.LinePlot();
                NPlot.LinePlot plotEntry = new NPlot.LinePlot();

                plotAlgo.AbscissaData = time;
                plotAlgo.DataSource   = valAlgo;
                plotAlgo.Label        = "Algorithm";
                plotAlgo.Color        = Color.Blue;

                _npSurface.Add(plotAlgo, NPlot.PlotSurface2D.XAxisPosition.Bottom,
                               NPlot.PlotSurface2D.YAxisPosition.Left);


                plotEntry.AbscissaData = time;
                plotEntry.DataSource   = valEntry;
                plotEntry.Label        = "Entry";
                plotEntry.Color        = Color.Red;

                _npSurface.Add(plotEntry, NPlot.PlotSurface2D.XAxisPosition.Bottom,
                               NPlot.PlotSurface2D.YAxisPosition.Left);
            }

            _npSurface.XAxis1.Label        = "Time";
            _npSurface.XAxis1.NumberFormat = "{0:##0}";
            _npSurface.XAxis1.LabelFont    = AxisFont;
            _npSurface.XAxis1.TickTextFont = TickFont;

            _npSurface.YAxis1.Label        = $"{tm}";
            _npSurface.YAxis1.NumberFormat = "{0:##0.0}";
            _npSurface.YAxis1.LabelFont    = AxisFont;
            _npSurface.YAxis1.TickTextFont = TickFont;


            NPlot.Legend npLegend = new NPlot.Legend();

            npLegend.AttachTo(NPlot.PlotSurface2D.XAxisPosition.Top,
                              NPlot.PlotSurface2D.YAxisPosition.Right);
            npLegend.VerticalEdgePlacement   = NPlot.Legend.Placement.Inside;
            npLegend.HorizontalEdgePlacement = NPlot.Legend.Placement.Outside;
            npLegend.BorderStyle             = NPlot.LegendBase.BorderType.Line;
            _npSurface.Legend = npLegend;

            _npSurface.Refresh();

            try
            {
                if (!Directory.Exists(Path))
                {
                    DirectoryInfo di = Directory.CreateDirectory(Path);
                    Console.WriteLine("The directory was created successfully at {0}.", Directory.GetCreationTime(Path));
                }
                var files = Directory.GetFiles($"{Path}/", $"*plot-{ta}-{tm}*.png");
                _npSurface.Bitmap.Save($"{Path}/plot-{ta}-{tm}-{files.Length}.png");
            }
            catch (Exception e)
            {
                Console.WriteLine("The process failed: {0}", e.ToString());
            }
        }
Ejemplo n.º 6
0
        private void RePlot()
        {
            nplot.Clear();

            // ensure user has selected both x and y
            if (Node == null || LabelX == null || LabelY == null)
                return;

            //find the associated col index
            int colx = -1, coly = -1, i = 0;
            foreach (DataGridViewColumn col in Data.Grid.Columns)
            {
                if (col.HeaderText == LabelX)
                    colx = i;
                if (col.HeaderText == LabelY)
                    coly = i;
                i++;
            }

            if (colx == -1 || coly == -1)
                return;

            // get the data from the gridview
            List<double> x = new List<double>(Data.Grid.Rows.Count);
            List<double> y = new List<double>(Data.Grid.Rows.Count);
            double tx, ty;
            foreach (DataGridViewRow row in Data.Grid.Rows)
            {
                try
                {
                    if (row.Cells[colx].Value == null || row.Cells[coly].Value == null)
                        continue;
                    tx = Double.Parse(row.Cells[colx].Value.ToString());
                    ty = Double.Parse(row.Cells[coly].Value.ToString());
                    x.Add(tx);
                    y.Add(ty);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }

            nplot.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;

            //Add a background grid for better chart readability.
            NPlot.Grid grid = new NPlot.Grid();
            grid.VerticalGridType = NPlot.Grid.GridType.Coarse;
            grid.HorizontalGridType = NPlot.Grid.GridType.Coarse;
            grid.MinorGridPen = new Pen(Color.Blue, 1.0f);
            grid.MajorGridPen = new Pen(Color.LightGray, 1.0f);
            nplot.Add(grid);

            //create a lineplot from it
            NPlot.LinePlot lp = new NPlot.LinePlot();
            lp.AbscissaData = x;
            lp.OrdinateData = y;
            nplot.Add(lp);

            //point plot for showing points
            NPlot.PointPlot pp = new NPlot.PointPlot();
            pp.AbscissaData = x;
            pp.OrdinateData = y;
            nplot.Add(pp);

            //format axes labels
            nplot.YAxis1.Label = LabelY;
            nplot.YAxis1.LabelFont = new Font(this.Font, FontStyle.Regular);
            nplot.YAxis1.LabelOffsetAbsolute = true;
            nplot.YAxis1.LabelOffset = 40;

            nplot.XAxis1.Label = LabelX;
            nplot.XAxis1.LabelFont = new Font(this.Font, FontStyle.Regular);
            nplot.XAxis1.HideTickText = false;
            nplot.Padding = 5;

            //enable dragging etc
            nplot.RightMenu = NPlot.Windows.PlotSurface2D.DefaultContextMenu;
            nplot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(false));
            nplot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag());
            nplot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag());

            nplot.Refresh();
        }