Exemplo n.º 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            myPlot.Clear();
            StepPlot sp1 = new StepPlot();

            sp1.OrdinateData = new int[] { 0, 1, 2 };
            sp1.AbscissaData = new int[] { 4, 5, 6 };
            sp1.Label        = "高度";
            sp1.Pen.Width    = 2;
            sp1.Pen.Color    = Color.Blue;
            myPlot.Add(sp1);
            myPlot.Refresh();
        }
Exemplo n.º 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            plot.Clear();   //对象名称为plot
            // --- Grid Code ---
            Grid mygrid = new Grid();

            mygrid.HorizontalGridType = Grid.GridType.None;
            mygrid.VerticalGridType   = Grid.GridType.Fine;
            plot.Add(mygrid);
            plot.Title = "K-line";
            //普通线
            StepPlot line = new StepPlot();

            line.Pen                  = new Pen(Color.Red, 1);
            line.OrdinateData         = new double[] { 0, 1, 0, 1, 1, 0.5, 1, 1, 1 };
            line.HideVerticalSegments = false;
            plot.Add(line);
            plot.Refresh();
            //蜡烛图
            int[]          opens  = { 1, 2, 1, 2, 1, 3 }; //开始数目
            double[]       closes = { 2, 2, 2, 1, 2, 1 }; //结束数目
            float[]        lows   = { 1, 1, 1, 1, 1, 1 }; //最高
            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;
            plot2.Title     = "蜡烛图";
            this.plot2.Add(cp);
            //水平+垂直 线
            plot3.Add(mygrid);
            HorizontalLine line3 = new HorizontalLine(10); //水平线
            VerticalLine   line4 = new VerticalLine(10);   //垂直线

            line3.LengthScale = 2.89f;
            line4.LengthScale = 0.89f;

            plot3.Title = "水平+垂直 线";

            plot3.Add(line3, 10);
            plot3.Add(line4, 1);



            return;
        }
Exemplo n.º 3
0
        public PlotWave() : base()
        {
            infoText  = "";
            infoText += "Sound Wave Example. Demonstrates - \n";
            infoText += " * StepPlot (centered) and HorizontalLine IDrawables \n";
            infoText += " * AxisDrag Interaction - try left clicking and dragging X or Y axes \n";
            infoText += " * Vertical & Horizontal GuideLines - without fragmentation problems! \n";
            infoText += " * Rubberband Selection - click and drag to zoom an area of the plot \n";
            infoText += " * Key actions : +,- zoom, left/right/up/down pan, Home restores original scale and origin";

            System.IO.Stream file =
                Assembly.GetExecutingAssembly().GetManifestResourceStream("SwfTest.Resources.sound.wav");

            System.Int16[] w = new short[5000];
            byte[]         a = new byte[10000];

            file.Read(a, 0, 10000);
            for (int i = 100; i < 5000; ++i)
            {
                w[i] = BitConverter.ToInt16(a, i * 2);
            }
            file.Close();

            plotSurface.Clear();

            plotSurface.AddInteraction(new AxisDrag());
            plotSurface.AddInteraction(new KeyActions());
            plotSurface.AddInteraction(new NPlot.PlotSelection(Color.Gray));
            plotSurface.AddInteraction(new VerticalGuideline(Color.Gray));
            plotSurface.AddInteraction(new HorizontalGuideline(Color.Gray));

            plotSurface.Add(new HorizontalLine(0.0, Color.LightBlue));

            StepPlot sp = new StepPlot();

            sp.DataSource = w;
            sp.Color      = Color.Yellow;
            sp.Center     = true;
            plotSurface.Add(sp);

            plotSurface.YAxis1.FlipTicksLabel = true;

            plotSurface.PlotBackColor    = Color.DarkBlue;
            plotSurface.Canvas.BackColor = Color.FromArgb(100, 100, 100);
            plotSurface.XAxis1.Color     = Color.White;
            plotSurface.YAxis1.Color     = Color.White;

            plotSurface.Refresh();
        }
Exemplo n.º 4
0
        public void CreatePlot(InteractivePlotSurface2D plotSurface)
        {
            //FileStream fs = new FileStream( @"c:\light.wav", System.IO.FileMode.Open );
            System.IO.Stream file =
                Assembly.GetExecutingAssembly().GetManifestResourceStream("DemoLib.Resources.light.wav");


            System.Int16[] w = new short[5000];
            byte[]         a = new byte[10000];
            file.Read(a, 0, 10000);
            for (int i = 100; i < 5000; ++i)
            {
                w[i] = BitConverter.ToInt16(a, i * 2);
            }

            file.Close();

            plotSurface.Clear();
            plotSurface.AddInteraction(new VerticalGuideline(Color.Gray));
            plotSurface.AddInteraction(new HorizontalGuideline(Color.Gray));
            plotSurface.AddInteraction(new PlotDrag(true, true));
            plotSurface.AddInteraction(new AxisDrag());

            plotSurface.Add(new HorizontalLine(0.0, Color.LightBlue));

            StepPlot sp = new StepPlot();

            sp.DataSource = w;
            sp.Color      = Color.Yellow;
            sp.Center     = true;
            plotSurface.Add(sp);

            plotSurface.YAxis1.FlipTicksLabel = true;

            plotSurface.OuterBackColor = Color.Black;
            plotSurface.PlotBackColor  = Color.DarkBlue;
            plotSurface.XAxis1.Color   = Color.White;
            plotSurface.YAxis1.Color   = Color.White;

            plotSurface.Refresh();
        }
Exemplo n.º 5
0
        public PlotMockup()
        {
            infoText  = "";
            infoText += "THE TEST (can your charting library handle this?) - \n";
            infoText += "NPlot demonstrates it can handle real world charting requirements.";

            // first of all, generate some mockup data.
            DataTable info = new DataTable("Store Information");

            info.Columns.Add("Index", typeof(int));
            info.Columns.Add("IndexOffsetLeft", typeof(float));
            info.Columns.Add("IndexOffsetRight", typeof(float));
            info.Columns.Add("StoreName", typeof(string));
            info.Columns.Add("BarBase", typeof(float));
            info.Columns.Add("StoreGrowth", typeof(float));
            info.Columns.Add("AverageGrowth", typeof(float));
            info.Columns.Add("ProjectedSales", typeof(float));

            float  barBase = 185.0f;
            Random r       = new Random();

            for (int i = 0; i < 18; ++i)
            {
                DataRow row = info.NewRow();
                row["Index"]            = i;
                row["IndexOffsetLeft"]  = (float)i - 0.1f;
                row["IndexOffsetRight"] = (float)i + 0.1f;
                row["StoreName"]        = "Store " + (i + 1).ToString();
                row["BarBase"]          = barBase;
                row["StoreGrowth"]      = barBase + ((r.NextDouble() - 0.1) * 20.0f);
                row["AverageGrowth"]    = barBase + ((r.NextDouble() - 0.1) * 15.0f);
                row["ProjectedSales"]   = barBase + (r.NextDouble() * 15.0f);
                info.Rows.Add(row);
                barBase += (float)r.NextDouble() * 4.0f;
            }

            plotSurface.Clear();

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

            // generate the grid
            Grid grid = new Grid();

            grid.VerticalGridType   = Grid.GridType.Coarse;
            grid.HorizontalGridType = Grid.GridType.None;
            grid.MajorGridPen       = new Pen(Color.Black, 1.0f);
            plotSurface.Add(grid);

            // generate the trendline
            LinePlot trendline = new LinePlot();

            trendline.DataSource   = info;
            trendline.AbscissaData = "Index";
            trendline.OrdinateData = "BarBase";
            trendline.Pen          = new Pen(Color.Black, 3.0f);
            trendline.Label        = "Trendline";
            plotSurface.Add(trendline);

            // draw store growth bars
            BarPlot storeGrowth = new BarPlot();

            storeGrowth.DataSource         = info;
            storeGrowth.AbscissaData       = "IndexOffsetLeft";
            storeGrowth.OrdinateDataTop    = "StoreGrowth";
            storeGrowth.OrdinateDataBottom = "BarBase";
            storeGrowth.Label     = "Store Growth";
            storeGrowth.FillBrush = NPlot.RectangleBrushes.Solid.Black;
            //storeGrowth.BorderPen = new Pen( Color.Black, 2.0f );
            plotSurface.Add(storeGrowth);

            // draw average growth bars
            BarPlot averageGrowth = new BarPlot();

            averageGrowth.DataSource         = info;
            averageGrowth.AbscissaData       = "IndexOffsetRight";
            averageGrowth.OrdinateDataBottom = "BarBase";
            averageGrowth.OrdinateDataTop    = "AverageGrowth";
            averageGrowth.Label     = "Average Growth";
            averageGrowth.FillBrush = NPlot.RectangleBrushes.Solid.Gray;
            //averageGrowth.BorderPen = new Pen( Color.Black, 2.0f );
            plotSurface.Add(averageGrowth);

            // generate the projected sales step line.
            StepPlot projected = new StepPlot();

            projected.DataSource           = info;
            projected.AbscissaData         = "Index";
            projected.OrdinateData         = "ProjectedSales";
            projected.Pen                  = new Pen(Color.Orange, 3.0f);
            projected.HideVerticalSegments = true;
            projected.Center               = true;
            projected.Label                = "Projected Sales";
            projected.WidthScale           = 0.7f;
            plotSurface.Add(projected);

            // generate the minimum target line.
            HorizontalLine minimumTargetLine = new HorizontalLine(218, new Pen(Color.Green, 3.5f));

            minimumTargetLine.Label        = "Minimum Target";
            minimumTargetLine.LengthScale  = 0.98f;
            minimumTargetLine.ShowInLegend = true;             // off by default for lines.
            plotSurface.Add(minimumTargetLine);

            // generate the preferred target line.
            HorizontalLine preferredTargetLine = new HorizontalLine(228, new Pen(Color.Blue, 3.5f));

            preferredTargetLine.Label        = "Preferred Target";
            preferredTargetLine.LengthScale  = 0.98f;
            preferredTargetLine.ShowInLegend = true;             // off by default for lines.
            plotSurface.Add(preferredTargetLine);

            // make some modifications so that chart matches requirements.
            // y axis.
            plotSurface.YAxis1.TicksIndependentOfPhysicalExtent = true;
            plotSurface.YAxis1.TickTextNextToAxis = false;
            //plotSurface.YAxis1.TicksAngle = 3.0f * (float)Math.PI / 2.0f; // Not required if TicksAngle bug #2000693 fixed
            ((LinearAxis)plotSurface.YAxis1).LargeTickStep      = 10.0;
            ((LinearAxis)plotSurface.YAxis1).NumberOfSmallTicks = 0;

            // x axis
            plotSurface.XAxis1.TicksIndependentOfPhysicalExtent = true;
            plotSurface.XAxis1.TickTextNextToAxis = false;
            //plotSurface.XAxis1.TicksAngle = (float)Math.PI / 2.0f; // Not required if TicksAngle bug #2000693 fixed
            LabelAxis la = new LabelAxis(plotSurface.XAxis1);

            for (int i = 0; i < info.Rows.Count; ++i)
            {
                la.AddLabel((string)info.Rows[i]["StoreName"], Convert.ToInt32(info.Rows[i]["Index"]));
            }
            la.TicksLabelAngle  = (float)90.0f;
            la.TicksBetweenText = true;
            plotSurface.XAxis1  = la;

            plotSurface.XAxis2 = (Axis)plotSurface.XAxis1.Clone();
            plotSurface.XAxis2.HideTickText  = true;
            plotSurface.XAxis2.LargeTickSize = 0;

            Legend l = new Legend();

            l.NumberItemsVertically = 2;
            l.AttachTo(XAxisPosition.Bottom, YAxisPosition.Left);
            l.HorizontalEdgePlacement = NPlot.Legend.Placement.Outside;
            l.VerticalEdgePlacement   = NPlot.Legend.Placement.Inside;
            l.XOffset     = 5;
            l.YOffset     = 50;
            l.BorderStyle = NPlot.LegendBase.BorderType.Line;

            plotSurface.Legend = l;

            plotSurface.Title =
                "Sales Growth Compared to\n" +
                "Average Sales Growth by Store Size - Rank Order Low to High";

            plotSurface.Refresh();
        }
Exemplo n.º 6
0
        public PlotParticles()
        {
            infoText  = "";
            infoText += "Particles Example. Demonstrates - \n";
            infoText += " * How to chart multiple data sets against multiple axes at the same time.";

            plotSurface.Clear();

            Grid mygrid = new Grid();

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

            // in this example we synthetize a particle distribution
            // in the x-x' phase space and plot it, with the rms Twiss
            // ellipse and desnity distribution
            const int Particle_Number = 500;

            float [] x = new float[Particle_Number];
            float [] y = new float[Particle_Number];
            // Twiss parameters for the beam ellipse
            // 5 mm mrad max emittance, 1 mm beta function
            float alpha, beta, gamma, emit;

            alpha = -2.0f;
            beta  = 1.0f;
            gamma = (1.0f + alpha * alpha) / beta;
            emit  = 4.0f;

            float da, xmax, xpmax;

            da    = -alpha / gamma;
            xmax  = (float)Math.Sqrt(emit / gamma);
            xpmax = (float)Math.Sqrt(emit * gamma);

            Random rand = new Random();

            // cheap randomizer on the unit circle
            for (int i = 0; i < Particle_Number; i++)
            {
                float r;
                do
                {
                    x[i] = (float)(2.0f * rand.NextDouble() - 1.0f);
                    y[i] = (float)(2.0f * rand.NextDouble() - 1.0f);
                    r    = (float)Math.Sqrt(x[i] * x[i] + y[i] * y[i]);
                } while (r > 1.0f);
            }

            // transform to the tilted twiss ellipse
            for (int i = 0; i < Particle_Number; ++i)
            {
                y[i] *= xpmax;
                x[i]  = x[i] * xmax + y[i] * da;
            }
            plotSurface.Title = "Beam Horizontal Phase Space and Twiss ellipse";

            PointPlot pp = new PointPlot();

            pp.OrdinateData = y;
            pp.AbscissaData = x;
            pp.Marker       = new Marker(Marker.MarkerType.FilledCircle, 4, new Pen(Color.Blue));
            plotSurface.Add(pp, XAxisPosition.Bottom, YAxisPosition.Left);

            // set axes
            LinearAxis lx = (LinearAxis)plotSurface.XAxis1;

            lx.Label = "Position - x [mm]";
            lx.NumberOfSmallTicks = 2;
            LinearAxis ly = (LinearAxis)plotSurface.YAxis1;

            ly.Label = "Divergence - x' [mrad]";
            ly.NumberOfSmallTicks = 2;

            // Draws the rms Twiss ellipse computed from the random data
            float [] xeli = new float [40];
            float [] yeli = new float [40];

            float a_rms, b_rms, g_rms, e_rms;

            Twiss(x, y, out a_rms, out b_rms, out g_rms, out e_rms);
            TwissEllipse(a_rms, b_rms, g_rms, e_rms, ref xeli, ref yeli);

            LinePlot lp = new LinePlot();

            lp.OrdinateData = yeli;
            lp.AbscissaData = xeli;
            plotSurface.Add(lp, XAxisPosition.Bottom, YAxisPosition.Left);
            lp.Pen = new Pen(Color.Red, 2.0f);
            // Draws the ellipse containing 100% of the particles
            // for a uniform distribution in 2D the area is 4 times the rms
            float [] xeli2 = new float [40];
            float [] yeli2 = new float [40];
            TwissEllipse(a_rms, b_rms, g_rms, 4.0F * e_rms, ref xeli2, ref yeli2);

            LinePlot lp2 = new LinePlot();

            lp2.OrdinateData = yeli2;
            lp2.AbscissaData = xeli2;
            plotSurface.Add(lp2, XAxisPosition.Bottom, YAxisPosition.Left);
            Pen p2 = new Pen(Color.Red, 2.0f);

            float [] pattern = { 5.0f, 40.0f };
            p2.DashPattern = pattern;
            lp2.Pen        = p2;

            // now bin the particle position to create beam density histogram
            float range, min, max;

            min   = (float)lx.WorldMin;
            max   = (float)lx.WorldMax;
            range = max - min;

            const int Nbin = 30;

            float [] xbin = new float[Nbin + 1];
            float [] xh   = new float[Nbin + 1];

            for (int j = 0; j <= Nbin; ++j)
            {
                xbin[j] = min + j * range;
                if (j < Nbin)
                {
                    xh[j] = 0.0F;
                }
            }
            for (int i = 0; i < Particle_Number; ++i)
            {
                if (x[i] >= min && x[i] <= max)
                {
                    int j;
                    j      = Convert.ToInt32(Nbin * (x[i] - min) / range);
                    xh[j] += 1;
                }
            }
            StepPlot sp = new StepPlot();

            sp.OrdinateData = xh;
            sp.AbscissaData = new StartStep(min, range / Nbin);
            sp.Center       = true;
            plotSurface.Add(sp, XAxisPosition.Bottom, YAxisPosition.Right);
            // axis formatting
            LinearAxis ly2 = (LinearAxis)plotSurface.YAxis2;

            ly2.WorldMin           = 0.0f;
            ly2.Label              = "Beam Density [a.u.]";
            ly2.NumberOfSmallTicks = 2;
            sp.Pen = new Pen(Color.Green, 2);

            // Finally, refreshes the plot
            plotSurface.Refresh();
        }
Exemplo n.º 7
0
        public StepPlotSample() : base()
        {
            infoText  = "";
            infoText += "Sound Wave Example. Demonstrates - \n";
            infoText += " * StepPlot (centered) and HorizontalLine IDrawables \n";
            infoText += " * Vertical ColorGradient plotBackground \n";
            //infoText += " * AxisDrag Interaction - try left clicking and dragging X or Y axes \n";
            //infoText += " * Vertical & Horizontal GuideLines - without fragmentation problems! \n";
            //infoText += " * Rubberband Selection - click and drag to zoom an area of the plot \n";
            //infoText += " * Key actions : +,- zoom, left/right/up/down pan, Home restores original scale and origin";

            Assembly asm = Assembly.GetExecutingAssembly();

            Stream file = asm.GetManifestResourceStream("Samples.Resources.sound.wav");

            byte[]         a = new byte[10000];
            System.Int16[] v = new short[5000];
            System.Int16[] w = new short[1000];

            file.Read(a, 0, 10000);
            for (int i = 100; i < 5000; ++i)
            {
                v[i] = BitConverter.ToInt16(a, i * 2);
            }
            file.Close();
            // Select only every 5th sample, so data size = 1000 points
            for (int i = 1; i < 1000; ++i)
            {
                w[i] = v[i * 5];
            }

            plotCanvas.Clear();

            plotCanvas.AddInteraction(new KeyActions());
            //plotCanvas.AddInteraction (new AxisDrag ());
            //plotCanvas.AddInteraction (new PlotSelection (Color.Gray));
            //plotCanvas.AddInteraction (new VerticalGuideline (Color.Gray));
            //plotCanvas.AddInteraction (new HorizontalGuideline (Color.Gray));

            plotCanvas.Add(new HorizontalLine(2500.0, Colors.LightBlue));

            StepPlot sp = new StepPlot();

            sp.DataSource = w;
            sp.Color      = Colors.Black;
            sp.Center     = true;
            plotCanvas.Add(sp);

            plotCanvas.YAxis1.FlipTickText = true;

            plotCanvas.Canvas.BackgroundColor = new Color(0.375, 0.375, 0.375);

            ColorGradient g = new ColorGradient();

            g.StartColor = new Color(0.5, 0.5, 1);
            g.EndColor   = new Color(0.5, 1, 0.5);
            plotCanvas.PlotBackGradient = g;

            plotCanvas.XAxis1.LineColor = Colors.White;
            plotCanvas.YAxis1.LineColor = Colors.White;

            PackStart(plotCanvas.Canvas, true);
            Label la = new Label(infoText);

            PackStart(la);
        }