Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public PriceAction()
        {
            plotSurface = new NPlot.Bitmap.PlotSurface2D(700, 500);

            string infoText = "";

            infoText += "Simple CandlePlot example. Demonstrates - \n";
            infoText += " * Setting candle plot datapoints using arrays \n";
            infoText += " * Plot Zoom interaction using MouseWheel ";

            plotSurface.Clear();

            FilledRegion fr = new FilledRegion(
                new VerticalLine(1.2),
                new VerticalLine(2.4));

            fr.Brush = Brushes.BlanchedAlmond;
            plotSurface.Add(fr);

            // note that arrays can be of any type you like.
            int[]          opens  = { 1, 2, 1, 2, 1, 3 };
            double[]       closes = { 2, 2, 2, 1, 2, 1 };
            float[]        lows   = { 0, 1, 1, 1, 0, 0 };
            System.Int64[] highs  = { 3, 2, 3, 3, 3, 4 };
            int[]          times  = { 0, 1, 2, 3, 4, 5 };

            CandlePlot cp = new CandlePlot();

            cp.CloseData    = closes;
            cp.OpenData     = opens;
            cp.LowData      = lows;
            cp.HighData     = highs;
            cp.AbscissaData = times;
            plotSurface.Add(cp);

            HorizontalLine line = new HorizontalLine(1.2);

            line.LengthScale = 0.89f;
            plotSurface.Add(line, -10);

            VerticalLine line2 = new VerticalLine(1.2);

            line2.LengthScale = 0.89f;
            plotSurface.Add(line2);

            plotSurface.AddInteraction(new PlotZoom());

            plotSurface.Title = "Line in the Title Number 1\nFollowed by another title line\n and another";
            plotSurface.Refresh();
        }
Exemplo n.º 3
0
        public void LoadPriceBars(Bookmark <IPriceBar> priceBars)
        {
            int maxIndex = priceBars.Count;

            double[] opens  = new double[maxIndex];
            double[] highs  = new double[maxIndex];
            double[] lows   = new double[maxIndex];
            double[] closes = new double[maxIndex];
            double[] times  = new double[maxIndex];

            for (int i = 0; i < maxIndex; i++)
            {
                IPriceBar priceBar = priceBars[i];
                opens[i]  = priceBar.Open;
                highs[i]  = priceBar.High;
                lows[i]   = priceBar.Low;
                closes[i] = priceBar.Close;
                times[i]  = i;
            }
            CandlePlot cp = new CandlePlot();

            cp.OpenData     = opens;
            cp.HighData     = highs;
            cp.LowData      = lows;
            cp.CloseData    = closes;
            cp.AbscissaData = times;

            plotSurface.Clear();
            plotSurface.Add(cp);

            plotSurface.Refresh();
        }
Exemplo n.º 4
0
        public void ShowSpectrum(string Filename)
        {
            try
            {
                while (!_spectrumProcess.HasExited)
                {
                    Thread.Sleep(50);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Failed to get spectrum results");
                return;
            }
            LinePlot  lp = new LinePlot();
            PointPlot pp = new PointPlot();

            NPlot.Bitmap.PlotSurface2D npSurface = new NPlot.Bitmap.PlotSurface2D(1000, 1000);

            try
            {
                Tuple <float[], float[]> Data = ReadFile(Filename);
                if (Data == null)
                {
                    return;
                }
                lp.AbscissaData = Data.Item1;
                lp.DataSource   = Data.Item2;
                lp.Color        = System.Drawing.Color.Green;
                npSurface.Add(lp);
                npSurface.XAxis1.Label = "Frequncy [Hz]";
                npSurface.YAxis1.Label = "Power [db]";
                npSurface.Title        = "Central Frequncy = " + (_central_frequncy / 1e6).ToString() + " MHz - Bandwidth = " + (_rate / 1e6).ToString() + " MHz";
                npSurface.BackColor    = System.Drawing.Color.White;

                npSurface.Refresh();

                MemoryStream ms = new MemoryStream();
                npSurface.Bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                ms.Position = 0;
                Gtk.Application.Invoke(delegate
                {
                    Pixbuf p = new Gdk.Pixbuf(ms);

                    image.Pixbuf = p;
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
 protected override Image DoCreateChartImage()
 {
     var surface = new PlotSurface2D(Parameters.ChartWidth, Parameters.ChartHeight);
     var plot = new LinePlot
         {
             OrdinateData = Parameters.SeriaData.Select(t => t.Key).ToArray(),
             AbscissaData = Parameters.SeriaData.Select(t => t.Value).ToArray()
         };
     surface.Add(plot);
     surface.Refresh();
     return surface.Bitmap;
 }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Create a 2-dimensional surface plot of the specified statistic data.
        /// </summary>
        /// <param name="ordinateData">The Y-axis data values.</param>
        /// <param name="abscissaData">The X-axis data values.</param>
        /// <returns>The plot image bitmap.</returns>
		private static Bitmap Plot(IList ordinateData, IList abscissaData)
		{

			PlotSurface2D plotSurface2D = new PlotSurface2D(200, 200);
		    plotSurface2D.SmoothingMode = SmoothingMode.HighQuality;

		    LinePlot linePlot = new LinePlot(ordinateData, abscissaData);
			linePlot.ShadowColor = Color.Beige;
			linePlot.Pen = new Pen(Color.Blue);
			linePlot.Pen.Width = 1.0f;
			plotSurface2D.Add(linePlot);
			plotSurface2D.Refresh();
			return plotSurface2D.Bitmap;
		}
Exemplo n.º 8
0
        public void RefreshSpeed()
        {
            List <double> xVal = new List <double>();
            List <double> yVal = new List <double>();

            for (int x = 0; x < 100000; x++)
            {
                xVal.Add(x);
                yVal.Add(1 - x);
            }
            Stopwatch sw  = new Stopwatch();
            Stopwatch sw2 = new Stopwatch();
            LinePlot  p1  = new LinePlot(yVal, xVal);

            PlotSurface2D plot = new PlotSurface2D(640, 480);

            sw.Start();

            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);

            sw2.Start();
            plot.Refresh();
            sw2.Stop();
            sw.Stop();

            Console.WriteLine(sw2.Elapsed.TotalSeconds.ToString() + " seconds to refresh");
            Console.WriteLine(sw.Elapsed.TotalSeconds.ToString() + " seconds To add and refresh");
        }
        public void RefreshSpeed()
        {
            List<double> xVal = new List<double>();
            List<double> yVal = new List<double>();

            for (int x = 0; x < 100000; x++)
            {
                xVal.Add(x);
                yVal.Add(1 - x);
            }
            Stopwatch sw = new Stopwatch();
            Stopwatch sw2 = new Stopwatch();
            LinePlot p1 = new LinePlot(yVal, xVal);

            PlotSurface2D plot = new PlotSurface2D(640, 480);

            sw.Start();

            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);
            plot.Add(p1);

            sw2.Start();
            plot.Refresh();
            sw2.Stop();
            sw.Stop();

            Console.WriteLine(sw2.Elapsed.TotalSeconds.ToString() + " seconds to refresh");
            Console.WriteLine(sw.Elapsed.TotalSeconds.ToString() + " seconds To add and refresh");
        }
Exemplo n.º 10
0
        /// <summary>
        /// Create a 2-dimensional surface plot of the specified statistic data.
        /// </summary>
        /// <param name="ordinateData">The Y-axis data values.</param>
        /// <param name="abscissaData">The X-axis data values.</param>
        /// <returns>The plot image bitmap.</returns>
        private static Bitmap Plot(IList ordinateData, IList abscissaData)
        {
            PlotSurface2D plotSurface2D = new PlotSurface2D(200, 200);

            plotSurface2D.SmoothingMode = SmoothingMode.HighQuality;

            LinePlot linePlot = new LinePlot(ordinateData, abscissaData);

            linePlot.ShadowColor = Color.Beige;
            linePlot.Pen         = new Pen(Color.Blue);
            linePlot.Pen.Width   = 1.0f;
            plotSurface2D.Add(linePlot);
            plotSurface2D.Refresh();
            return(plotSurface2D.Bitmap);
        }
Exemplo n.º 11
0
        private void SaveFromConsoleApplication()
        {
            // simulate plotting from a console application
            var linePlot = new NPlot.PointPlot {
                DataSource = RandomWalk(20)
            };
            var surface = new NPlot.Bitmap.PlotSurface2D(400, 300);

            surface.BackColor = Color.White;
            surface.Add(linePlot);
            surface.Title        = $"Scatter Plot from a Console Application";
            surface.YAxis1.Label = "Vertical Axis Label";
            surface.XAxis1.Label = "Horizontal Axis Label";
            surface.Refresh();
            surface.Bitmap.Save("nplot-console-quickstart.png");
        }
Exemplo n.º 12
0
        private void InitPlot(out NPlot.Bitmap.PlotSurface2D npSurface, out Font AxisFont, out Font TickFont, out NPlot.Grid p, int width, int height)
        {
            npSurface = new NPlot.Bitmap.PlotSurface2D(width, height);
            npSurface.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            //Font definitions:
            AxisFont = new Font("Arial", 10);
            TickFont = new Font("Arial", 8);

            //Prepare PlotSurface:
            npSurface.Clear();
            npSurface.Title     = this.Title;
            npSurface.BackColor = System.Drawing.Color.White;

            //Left Y axis grid:
            p = new Grid();
            npSurface.Add(p, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            //string file = File.ReadAllText(@"C:\Users\abradu\Desktop\Personal\Flights\284F4A90C57F3FA3E04E364FE6ACB925.json");
            string file = File.ReadAllText(@"C:\Users\abradu\Desktop\Personal\Flights\20056AD50DEFACE5A912E9076752BA70.json");

            Blackbox bb = new JavaScriptSerializer().Deserialize <Blackbox>(file);

            bb.ConvertToNatives();
            bb.SVT();

            for (int i = 0; i < bb.altitude.Count; i++)
            {
                bb.altitude[i] = bb.altitude[i] / 1000;
            }

            NPlot.Bitmap.PlotSurface2D npSurface = new NPlot.Bitmap.PlotSurface2D(10000, 1000);
            NPlot.LinePlot             npPlot1   = new LinePlot();
            NPlot.LinePlot             npPlot2   = new LinePlot();
            NPlot.LinePlot             npPlot3   = new LinePlot();
            NPlot.LinePlot             npPlot4   = new LinePlot();
            NPlot.LinePlot             npPlot5   = new LinePlot();

            npSurface.Clear();
            npSurface.Title     = "Line Graph";
            npSurface.BackColor = System.Drawing.Color.White;

            //Left Y axis grid:
            NPlot.Grid          p = new Grid();
            NPlot.HistogramPlot h = new HistogramPlot();
            npSurface.Add(p, NPlot.PlotSurface2D.XAxisPosition.Bottom,
                          NPlot.PlotSurface2D.YAxisPosition.Left);

            //Phi:
            npPlot1.AbscissaData = bb.time;
            npPlot1.DataSource   = bb.angle_phi;
            npPlot1.Label        = "Phi";
            npPlot1.Color        = System.Drawing.Color.Blue;

            npSurface.Add(npPlot1, NPlot.PlotSurface2D.XAxisPosition.Bottom,
                          NPlot.PlotSurface2D.YAxisPosition.Left);

            //Phi:
            npPlot2.AbscissaData = bb.time;
            npPlot2.DataSource   = bb.angle_psi;
            npPlot2.Label        = "Psi";
            npPlot2.Color        = System.Drawing.Color.Red;

            npSurface.Add(npPlot2, NPlot.PlotSurface2D.XAxisPosition.Bottom,
                          NPlot.PlotSurface2D.YAxisPosition.Left);

            //Theta:
            npPlot3.AbscissaData = bb.time;
            npPlot3.DataSource   = bb.angle_theta;
            npPlot3.Label        = "Theta";
            npPlot3.Color        = System.Drawing.Color.Green;

            npSurface.Add(npPlot3, NPlot.PlotSurface2D.XAxisPosition.Bottom,
                          NPlot.PlotSurface2D.YAxisPosition.Left);

            //Speed:
            npPlot4.AbscissaData = bb.time;
            npPlot4.DataSource   = bb.SpeedVsTheta;
            npPlot4.Label        = "Speed";
            npPlot4.Color        = System.Drawing.Color.Black;

            npSurface.Add(npPlot4, NPlot.PlotSurface2D.XAxisPosition.Bottom,
                          NPlot.PlotSurface2D.YAxisPosition.Left);

            ////Alti:
            //npPlot5.AbscissaData = bb.time;
            //npPlot5.DataSource = bb.altitude;
            //npPlot5.Label = "Alt";
            //npPlot5.Color = System.Drawing.Color.Orange;

            //npSurface.Add(npPlot5, NPlot.PlotSurface2D.XAxisPosition.Bottom,
            //      NPlot.PlotSurface2D.YAxisPosition.Left);

            npSurface.Refresh();

            MemoryStream memStream = new MemoryStream();

            npSurface.Bitmap.Save(memStream, System.Drawing.Imaging.ImageFormat.Gif);

            FileStream fs = new FileStream(@"D:\file.gif", FileMode.Create);

            memStream.WriteTo(fs);

            //Console.WriteLine("Done");
            //Console.ReadLine();
        }
Exemplo n.º 15
0
        private void InitPlot(out NPlot.Bitmap.PlotSurface2D npSurface, out Font AxisFont, out Font TickFont, out NPlot.Grid p, int width, int height)
        {
            npSurface = new NPlot.Bitmap.PlotSurface2D(width, height);
            npSurface.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            //Font definitions:
            AxisFont = new Font("Arial", 10);
            TickFont = new Font("Arial", 8);

            //Prepare PlotSurface:
            npSurface.Clear();
            npSurface.Title = this.Title;
            npSurface.BackColor = System.Drawing.Color.White;

            //Left Y axis grid:
            p = new Grid();
            npSurface.Add(p, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left);
        }