public void InitDataToChart() { //图例 legend = new Legend(); legend.AttachTo(PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Left); legend.VerticalEdgePlacement = Legend.Placement.Inside; legend.HorizontalEdgePlacement = Legend.Placement.Outside; legend.YOffset = -5; legend.BorderStyle = LegendBase.BorderType.Line; legend.NumberItemsHorizontally = 2; legend.Font = new Font(FontFamily.GenericSerif, 8, FontStyle.Regular); legend.AutoScaleText = false; //网格 grid = new Grid(); grid.HorizontalGridType = Grid.GridType.Fine; grid.VerticalGridType = Grid.GridType.Fine; grid.MajorGridPen.Color = Color.Silver; grid.MinorGridPen.Color = Color.Silver; ///////////////////////////////////////////// //直线图 linePlot = new LinePlot(); linePlot.OrdinateData = cart.regressY; linePlot.AbscissaData = xList; linePlot.Color = Color.Orange; linePlot.Pen.Width = 2.0f; //点图 Marker marker = new Marker(Marker.MarkerType.FilledCircle, 3, new Pen(Color.Blue)); marker.FillBrush = new SolidBrush(Color.RoyalBlue); pointPlot = new PointPlot(marker); pointPlot.AbscissaData = xList; pointPlot.OrdinateData = yList; pointPlot.ShowInLegend = false; if(cart.regressXYB>0) linePlot.Label = yLabel + "=" + cart.regressXYA.ToString("F2") + "*" + xLabel + "+" + cart.regressXYB.ToString("F2") + ",R=" + cart.correlationXY.ToString("F2"); else linePlot.Label = yLabel + "=" + cart.regressXYA.ToString("F2") + "*" + xLabel + cart.regressXYB.ToString("F2") + ",R=" + cart.correlationXY; label1.Text = xLabel + "(m:" + cart.xMean.ToString("F1") + ",s':" + cart.xVar.ToString("F1") + ") " + yLabel + "(m:" + cart.yMean.ToString("F1") + ",s':" + cart.yVar.ToString("F1") + ")"; //添加 chart.Add(grid); chart.Add(linePlot); chart.Add(pointPlot); //设置属性 chart.XAxis1.Label = xLabel+":"+xUnit; chart.YAxis1.Label = yLabel+":"+yUnit; chart.YAxis1.LabelOffsetAbsolute = true; chart.Padding = 5; chart.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalGuideline()); chart.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60)); chart.PlotBackColor = Color.White; chart.BackColor = System.Drawing.SystemColors.Control; chart.XAxis1.Color = Color.Black; chart.YAxis1.Color = Color.Black; chart.Legend = legend; chart.LegendZOrder = 1; chart.Refresh(); }
public void PlotQE() { string lines = "Cs2Te Photocathode QE evolution Example. Demonstrates - * LabelPointPlot (allows text to be associated with points) * PointPlot droplines * LabelAxis * PhysicalSpacingMin property of LabelAxis.You cannot interact with this chart"; infoBox.Text = lines; qeExampleTimer.Enabled = true; plotSurface.Clear(); int len = 24; string[] s = new string[len]; PlotQEExampleValues = new double[len]; PlotQEExampleTextValues = new string[len]; Random r = new Random(); for (int i=0; i<len;i++) { PlotQEExampleValues[i] = 8.0f + 12.0f * (double)r.Next(10000) / 10000.0f; if (PlotQEExampleValues[i] > 18.0f) { PlotQEExampleTextValues[i] = "KCsTe"; } else { PlotQEExampleTextValues[i] = ""; } s[i] = i.ToString("00") + ".1"; } PointPlot pp = new PointPlot(); pp.DataSource = PlotQEExampleValues; pp.Marker = new Marker( Marker.MarkerType.Square, 10 ); pp.Marker.DropLine = true; pp.Marker.Pen = new Pen(Color.CornflowerBlue); pp.Marker.Filled = false; plotSurface.Add( pp ); LabelPointPlot tp1 = new LabelPointPlot(); tp1.DataSource = PlotQEExampleValues; tp1.TextData = PlotQEExampleTextValues; tp1.LabelTextPosition = LabelPointPlot.LabelPositions.Above; tp1.Marker = new Marker( Marker.MarkerType.None, 10 ); plotSurface.Add( tp1 ); LabelAxis la = new LabelAxis( plotSurface.XAxis1 ); for (int i=0; i<len; ++i) { la.AddLabel( s[i], i ); } la.TickTextFont = new Font( FontFamily.GenericSerif, 7 ,FontStyle.Regular); la.PhysicalSpacingMin = 25; plotSurface.XAxis1 = la; plotSurface.Title = "Cs2Te Photocathode QE evolution"; plotSurface.TitleFont = new Font(FontFamily.GenericSerif, 15, FontStyle.Regular); plotSurface.XAxis1.WorldMin = -1.0f; plotSurface.XAxis1.WorldMax = len; plotSurface.XAxis1.LabelFont = new Font(FontFamily.GenericSerif, 10, FontStyle.Regular); plotSurface.XAxis1.Label = "Cathode ID"; plotSurface.YAxis1.Label = "QE [%]"; plotSurface.YAxis1.LabelFont = new Font(FontFamily.GenericSerif, 10, FontStyle.Regular); plotSurface.YAxis1.TickTextFont = new Font(FontFamily.GenericSerif, 10, FontStyle.Regular); plotSurface.YAxis1.WorldMin = 0.0; plotSurface.YAxis1.WorldMax= 25.0; plotSurface.XAxis1.TicksLabelAngle = 60.0f; plotSurface.XAxis1.LabelOffset = 0; plotSurface.YAxis1.LabelOffset = 0; plotSurface.Refresh(); }
public void PlotMarkers() { string lines = "Markers Example. Demonstrates - * PointPlot and the available marker types * Legends, and how to place them."; infoBox.Text = lines; plotSurface.Clear(); double[] y = new double[1] {1.0f}; foreach (String i in Marker.getTypes()) { Marker m = new Marker( (Marker.MarkerType)Enum.Parse(typeof(Marker.MarkerType), i,true), 8 ); double[] x = new double[1]; x[0] = (double) m.Type; PointPlot pp = new PointPlot(); pp.OrdinateData = y; pp.AbscissaData = x; pp.Marker = m; pp.Label = m.Type.ToString(); plotSurface.Add( pp ); } plotSurface.Title = "Markers"; plotSurface.YAxis1.Label = "Index"; plotSurface.XAxis1.Label = "Marker"; plotSurface.YAxis1.WorldMin = 0.0f; plotSurface.YAxis1.WorldMax = 2.0f; plotSurface.XAxis1.WorldMin -= 1.0f; plotSurface.XAxis1.WorldMax += 1.0f; Legend legend = new Legend(); legend.AttachTo( PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Right ); legend.VerticalEdgePlacement = Legend.Placement.Outside; legend.HorizontalEdgePlacement = Legend.Placement.Inside; legend.XOffset = 5; // note that these numbers can be negative. legend.YOffset = 0; plotSurface.Legend = legend; plotSurface.XAxis1.LabelOffset = 0; plotSurface.YAxis1.LabelOffset = 0; plotSurface.Refresh(); }
public void PlotParticles() { string lines = "Particles Example. Demonstrates - * How to chart multiple data sets against multiple axes at the same time."; infoBox.Text = lines; 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, PlotSurface2D.XAxisPosition.Bottom, PlotSurface2D.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, PlotSurface2D.XAxisPosition.Bottom, PlotSurface2D.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, PlotSurface2D.XAxisPosition.Bottom, PlotSurface2D.YAxisPosition.Left ); Pen p2 = new Pen( Color.Red, 2.0f ); 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 dx = range / Nbin; 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, PlotSurface2D.XAxisPosition.Bottom, PlotSurface2D.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 ); plotSurface.XAxis1.LabelOffset = 0; plotSurface.YAxis1.LabelOffset = 0; // Finally, refreshes the plot plotSurface.Refresh(); }
private void PlotSincFunction() { string lines = "Sinc Function Example. Demonstrates - * Charting line and point plot at the same time. * Adding a legend."; infoBox.Text = lines; plotSurface.Clear(); // clear everything. reset fonts. remove plot components etc. System.Random r = new Random(); double[] a = new double[100]; double[] b = new double[100]; double mult = 0.00001f; for( int i=0; i<100; ++i ) { a[i] = ((double)r.Next(1000)/5000.0f-0.1f)*mult; if (i == 50 ) { b[i] = 1.0f*mult; } else { b[i] = (double)Math.Sin((((double)i-50.0f)/4.0f))/(((double)i-50.0f)/4.0f); b[i] *= mult; } a[i] += b[i]; } Marker m = new Marker(Marker.MarkerType.Cross1,6,new Pen(Color.Blue,2.0F)); PointPlot pp = new PointPlot( m ); pp.OrdinateData = a; pp.AbscissaData = new StartStep( -500.0, 10.0 ); pp.Label = "Random"; plotSurface.Add(pp); LinePlot lp = new LinePlot(); lp.OrdinateData = b; lp.AbscissaData = new StartStep( -500.0, 10.0 ); lp.Pen = new Pen( Color.Red, 2.0f ); plotSurface.Add(lp); plotSurface.Title = "Sinc Function"; plotSurface.YAxis1.Label = "Magnitude"; plotSurface.XAxis1.Label = "Position"; Legend legend = new Legend(); legend.AttachTo( PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Left ); legend.VerticalEdgePlacement = Legend.Placement.Inside; legend.HorizontalEdgePlacement = Legend.Placement.Inside; legend.YOffset = 8; plotSurface.Legend = legend; plotSurface.LegendZOrder = 1; // default zorder for adding idrawables is 0, so this puts legend on top. plotSurface.XAxis1.LabelOffset = 0; plotSurface.YAxis1.LabelOffset = 0; plotSurface.Refresh(); }