示例#1
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);
        }
示例#2
0
        public void InitCurve()
        {
            plotSurface2D1.Clear();
       
            NPlot.Grid mygrid = new NPlot.Grid();//新建网格
            mygrid.VerticalGridType = NPlot.Grid.GridType.Coarse;//横轴方向网格类型Coarse为粗糙型,Fine为细密型,None没有网格
            Pen majorGridPen = new Pen(Color.LightGray);//网格画笔(定义颜色)
            float[] pattern = { 2.0f, 1.0f };//画笔短划线和空白区域的数组
            majorGridPen.DashPattern = pattern;
            mygrid.MajorGridPen = majorGridPen;//MajorGridPen为Coarse对应画笔,MinorGridPen为Fine对应画笔
            plotSurface2D1.Add(mygrid);

            plotSurface2D1.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            plotSurface2D1.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag());

            plotSurface2D1.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag());

            plotSurface2D1.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(false));

            plotSurface2D1.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.MouseWheelZoom());

            plotSurface2D1.RightMenu = NPlot.Windows.PlotSurface2D.DefaultContextMenu;

            plotSurface2D1.RightMenu.Menu.MenuItems.Add(new MenuItem("-"));

            plotSurface2D1.RightMenu.Menu.MenuItems.Add(new MenuItem("更换曲线", mnuReplaceCurve_Click));

            plotSurface2D1.RightMenu.Menu.MenuItems.Add(new MenuItem("增加曲线", mnuAddCurve_Click));

            plotSurface2D1.RightMenu.Menu.MenuItems.Add(new MenuItem("删除曲线", mnuDeleteCurve_Click));

            plotSurface2D1.PlotBackColor = Color.White;

            NPlot.Legend legend = new NPlot.Legend();
            legend.AttachTo(PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Left);
            legend.VerticalEdgePlacement = NPlot.Legend.Placement.Inside;
            legend.HorizontalEdgePlacement = NPlot.Legend.Placement.Inside;
            legend.YOffset = 8;
            legend.XOffset = 8;
            legend.BorderStyle = LegendBase.BorderType.Line;

            plotSurface2D1.Legend = legend;
            plotSurface2D1.LegendZOrder = 0;
        }
示例#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);
        }
示例#4
0
        public void InitAction()
        {
            plotSurface2D1.Clear();

            NPlot.Grid mygrid = new NPlot.Grid();//新建网格
            mygrid.VerticalGridType = NPlot.Grid.GridType.Coarse;//横轴方向网格类型Coarse为粗糙型,Fine为细密型,None没有网格
            Pen majorGridPen = new Pen(Color.LightGray);//网格画笔(定义颜色)
            float[] pattern = { 2.0f, 1.0f };//画笔短划线和空白区域的数组
            majorGridPen.DashPattern = pattern;
            mygrid.MajorGridPen = majorGridPen;//MajorGridPen为Coarse对应画笔,MinorGridPen为Fine对应画笔
            plotSurface2D1.Add(mygrid);

            // 启动默认的右键菜单功能
            plotSurface2D1.RightMenu = NPlot.Windows.PlotSurface2D.DefaultContextMenu;

            plotSurface2D1.RightMenu.Menu.MenuItems.Add(new MenuItem("-"));

            plotSurface2D1.RightMenu.Menu.MenuItems.Add(new MenuItem("更换曲线", mnuReplaceCurve_Click));

            plotSurface2D1.RightMenu.Menu.MenuItems.Add(new MenuItem("增加曲线", mnuAddCurve_Click));

            plotSurface2D1.RightMenu.Menu.MenuItems.Add(new MenuItem("删除曲线", mnuDeleteCurve_Click));

            //背景颜色
            plotSurface2D1.PlotBackColor = Color.White;

            NPlot.Legend legend = new NPlot.Legend();//图例
            legend.AttachTo(PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Right);//图例位置
            legend.VerticalEdgePlacement = NPlot.Legend.Placement.Inside;
            legend.HorizontalEdgePlacement = NPlot.Legend.Placement.Inside;
            legend.YOffset = 8;
            legend.XOffset = -8;
            legend.BorderStyle = LegendBase.BorderType.Line;

            plotSurface2D1.Legend = legend;
            plotSurface2D1.LegendZOrder = 0; // default zorder for adding idrawables is 0, so this puts legend on top.
        }
示例#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());
            }
        }
示例#6
0
        // Erzeugt in einem Bitmap den zu plotenden Graphen

        public Image drawChart()
        {
            Bitmap bm = new Bitmap(PanelSize.Width, PanelSize.Height);

            using (Graphics g = Graphics.FromImage(bm))
            {
                //Rectangle allRect = new Rectangle(0, 0, PanelSize.Width, PanelSize.Height);
                //g.FillRectangle(Brushes.White, allRect);

                NPlot.Bitmap.PlotSurface2D plotSurface = new NPlot.Bitmap.PlotSurface2D(bm);
                plotSurface.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                // Achsen definieren

                if (_XAxisBottomType == AxisType.linear)
                {
                    plotSurface.XAxis1 = new NPlot.LinearAxis();
                }
                if (_XAxisBottomType == AxisType.log10)
                {
                    plotSurface.XAxis1 = new NPlot.LogAxis();
                }
                else if (_XAxisBottomType == AxisType.label)
                {
                    NPlot.LabelAxis      lA      = new NPlot.LabelAxis();
                    IEnumerator <string> elabels = _XAxisBottomLabels.GetEnumerator();
                    elabels.Reset();
                    IEnumerator <double> evalues = _XAxisBottomSeries.GetEnumerator();
                    evalues.Reset();
                    double minValue = double.MaxValue;
                    double maxValue = double.MinValue;
                    while (elabels.MoveNext() && evalues.MoveNext())
                    {
                        lA.AddLabel(elabels.Current, evalues.Current);
                        minValue = Math.Min(minValue, evalues.Current);
                        maxValue = Math.Max(maxValue, evalues.Current);
                    }
                    double puffer = (maxValue - minValue) * 0.05;
                    lA.WorldMin        = minValue - puffer;
                    lA.WorldMax        = maxValue + puffer;
                    plotSurface.XAxis1 = lA;
                }

                if (_XAxisBottomType != AxisType.undef)
                {
                    plotSurface.XAxis1.Label        = XAxis1Label;
                    plotSurface.XAxis1.TickTextFont = TickTextFont;
                    plotSurface.XAxis1.LabelFont    = LabelFont;
                }

                if (_XAxisTopType == AxisType.linear)
                {
                    plotSurface.XAxis2 = new NPlot.LinearAxis();
                }
                else if (_XAxisTopType == AxisType.log10)
                {
                    plotSurface.XAxis2 = new NPlot.LogAxis();
                }
                else if (_XAxisTopType == AxisType.label)
                {
                    NPlot.LabelAxis      lA      = new NPlot.LabelAxis();
                    IEnumerator <string> elabels = _XAxisTopLabels.GetEnumerator();
                    elabels.Reset();
                    IEnumerator <double> evalues = _XAxisTopSeries.GetEnumerator();
                    evalues.Reset();
                    while (elabels.MoveNext() && evalues.MoveNext())
                    {
                        lA.AddLabel(elabels.Current, evalues.Current);
                    }
                    plotSurface.XAxis2 = lA;
                }

                if (_XAxisTopType != AxisType.undef)
                {
                    plotSurface.XAxis2.Label        = XAxis2Label;
                    plotSurface.XAxis2.TickTextFont = TickTextFont;
                    plotSurface.XAxis2.LabelFont    = LabelFont;
                }

                if (_YAxisLeftType == AxisType.linear)
                {
                    plotSurface.YAxis1 = new NPlot.LinearAxis();
                }
                else if (_YAxisLeftType == AxisType.log10)
                {
                    plotSurface.YAxis1 = new NPlot.LogAxis();
                }
                else if (_YAxisLeftType == AxisType.label)
                {
                    NPlot.LabelAxis      lA      = new NPlot.LabelAxis();
                    IEnumerator <string> elabels = _YAxisLeftLabels.GetEnumerator();
                    elabels.Reset();
                    IEnumerator <double> evalues = _YAxisLeftSeries.GetEnumerator();
                    evalues.Reset();
                    while (elabels.MoveNext() && evalues.MoveNext())
                    {
                        lA.AddLabel(elabels.Current, evalues.Current);
                    }
                    plotSurface.YAxis1 = lA;
                }

                if (plotSurface.YAxis1 != null)
                {
                    plotSurface.YAxis1.AutoScaleTicks = Autozoom;
                    plotSurface.YAxis1.Label          = YAxis1Label;
                    plotSurface.YAxis1.LabelFont      = LabelFont;
                    plotSurface.YAxis1.TickTextFont   = TickTextFont;
                    if (!Autozoom)
                    {
                        plotSurface.YAxis1.WorldMax = YMax;
                        plotSurface.YAxis1.WorldMin = YMin;
                    }
                }

                if (_YAxisRightType == AxisType.linear)
                {
                    plotSurface.YAxis2 = new NPlot.LinearAxis();
                }
                else if (_YAxisRightType == AxisType.log10)
                {
                    plotSurface.YAxis2 = new NPlot.LogAxis();
                }
                else if (_YAxisRightType == AxisType.label)
                {
                    NPlot.LabelAxis      lA      = new NPlot.LabelAxis();
                    IEnumerator <string> elabels = _YAxisRightLabels.GetEnumerator();
                    elabels.Reset();
                    IEnumerator <double> evalues = _YAxisRightSeries.GetEnumerator();
                    evalues.Reset();
                    while (elabels.MoveNext() && evalues.MoveNext())
                    {
                        lA.AddLabel(elabels.Current, evalues.Current);
                    }
                    plotSurface.YAxis2 = lA;
                }

                if (plotSurface.YAxis2 != null)
                {
                    plotSurface.YAxis2.AutoScaleTicks = Autozoom;
                    plotSurface.YAxis2.Label          = YAxis2Label;
                    plotSurface.YAxis2.LabelFont      = LabelFont;
                    plotSurface.YAxis2.TickTextFont   = TickTextFont;
                    if (!Autozoom)
                    {
                        plotSurface.YAxis2.WorldMax = YMax;
                        plotSurface.YAxis2.WorldMin = YMin;
                    }
                }

                // Graphen hinzufügen

                foreach (MyPlot my in plots)
                {
                    plotSurface.Add(my.plot, my.XAxisPosition, my.YAxisPosition);
                }

                // Titel und Achsbeschrigtungen hinzufügen
                plotSurface.Title     = Title;
                plotSurface.TitleFont = TitleFont;

                // Legende hinzufügen
                NPlot.Legend legende = new NPlot.Legend();
                plotSurface.Legend = legende;

                // Gitternetzlinien hinzufügen
                NPlot.Grid grid = new NPlot.Grid();

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


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

            return(bm);
        }
示例#7
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();
        }