/// <summary> /// Constructor /// </summary> /// <param name="lp1">LinePlot that provides bounds to filled region [upper or lower]</param> /// <param name="lp2">LinePlot that provides bounds to filled region [upper or lower]</param> /// <remarks>TODO: make this work with other plot types.</remarks> public FilledRegion(LinePlot lp1, LinePlot lp2) { lp1_ = lp1; lp2_ = lp2; }
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 PlotMockup() { string lines ="THE TEST (can your charting library handle this?) - xuzhenzhen.com.chart demonstrates it can handle real world charting requirements."; infoBox.Text = lines; // 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(); // 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 = xuzhenzhen.com.chart.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 = xuzhenzhen.com.chart.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; ((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; 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( xuzhenzhen.com.chart.PlotSurface2D.XAxisPosition.Bottom, xuzhenzhen.com.chart.PlotSurface2D.YAxisPosition.Left ); l.HorizontalEdgePlacement = xuzhenzhen.com.chart.Legend.Placement.Outside; l.VerticalEdgePlacement = xuzhenzhen.com.chart.Legend.Placement.Inside; l.XOffset = 5; l.YOffset = 50; l.BorderStyle = xuzhenzhen.com.chart.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.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(); }
public void PlotLogAxis() { string lines = "Log Example. Demonstrates - * How to chart data against log axes and linear axes at the same time."; infoBox.Text = lines; plotSurface.Clear(); // draw a fine grid. Grid fineGrid = new Grid(); fineGrid.VerticalGridType = Grid.GridType.Fine; fineGrid.HorizontalGridType = Grid.GridType.Fine; plotSurface.Add( fineGrid ); const int npt = 101; float[] x = new float[npt]; float[] y = new float[npt]; float step = 0.1f; for (int i=0; i<npt; ++i) { x[i] = i*step - 5.0f; y[i] = (float)Math.Pow( 10.0, x[i] ); } float xmin = x[0]; float xmax = x[npt-1]; float ymin = (float)Math.Pow( 10.0, xmin ); float ymax = (float)Math.Pow( 10.0, xmax ); LinePlot lp = new LinePlot(); lp.OrdinateData = y; lp.AbscissaData = x; lp.Pen = new Pen( Color.Red ); plotSurface.Add( lp ); LogAxis loga = new LogAxis( plotSurface.YAxis1 ); loga.WorldMin = ymin; loga.WorldMax = ymax; loga.AxisColor = Color.Red; loga.LabelColor = Color.Red; loga.TickTextColor = Color.Red; loga.LargeTickStep = 1.0f; loga.Label = "10^x"; plotSurface.YAxis1 = loga; LinePlot lp1 = new LinePlot(); lp1.OrdinateData = y; lp1.AbscissaData = x; lp1.Pen = new Pen( Color.Blue ); plotSurface.Add( lp1, PlotSurface2D.XAxisPosition.Bottom, PlotSurface2D.YAxisPosition.Right ); LinearAxis lin = new LinearAxis( plotSurface.YAxis2 ); lin.WorldMin = ymin; lin.WorldMax = ymax; lin.AxisColor = Color.Blue; lin.LabelColor = Color.Blue; lin.TickTextColor = Color.Blue; lin.Label = "10^x"; plotSurface.YAxis2 = lin; LinearAxis lx = (LinearAxis)plotSurface.XAxis1; lx.WorldMin = xmin; lx.WorldMax = xmax; lx.Label = "x"; //((LogAxis)plotSurface.YAxis1).LargeTickStep = 2; plotSurface.Title = "Mixed Linear/Log Axes"; plotSurface.XAxis1.LabelOffset = 0; plotSurface.YAxis1.LabelOffset = 0; plotSurface.Refresh(); }
public void PlotLogLog() { string lines ="LogLog Example. Demonstrates - * How to chart data against log axes and linear axes at the same time."; infoBox.Text = lines; // log log plot plotSurface.Clear(); Grid mygrid = new Grid(); mygrid.HorizontalGridType = Grid.GridType.Fine; mygrid.VerticalGridType = Grid.GridType.Fine; plotSurface.Add(mygrid); int npt = 101; float [] x = new float[npt]; float [] y = new float[npt]; float step=0.1f; // plot a power law on the log-log scale for (int i=0; i<npt; ++i) { x[i] = (i+1)*step; y[i] = x[i]*x[i]; } float xmin = x[0]; float xmax = x[npt-1]; float ymin = y[0]; float ymax = y[npt-1]; LinePlot lp = new LinePlot(); lp.OrdinateData = y; lp.AbscissaData = x; lp.Pen = new Pen( Color.Red ); plotSurface.Add( lp ); // axes // x axis LogAxis logax = new LogAxis( plotSurface.XAxis1 ); logax.WorldMin = xmin; logax.WorldMax = xmax; logax.AxisColor = Color.Red; logax.LabelColor = Color.Red; logax.TickTextColor = Color.Red; logax.LargeTickStep = 1.0f; logax.Label = "x"; plotSurface.XAxis1 = logax; // y axis LogAxis logay = new LogAxis( plotSurface.YAxis1 ); logay.WorldMin = ymin; logay.WorldMax = ymax; logay.AxisColor = Color.Red; logay.LabelColor = Color.Red; logay.TickTextColor = Color.Red; logay.LargeTickStep = 1.0f; logay.Label = "x^2"; plotSurface.YAxis1 = logay; LinePlot lp1 = new LinePlot(); lp1.OrdinateData = y; lp1.AbscissaData = x; lp1.Pen = new Pen( Color.Blue ); plotSurface.Add( lp1, PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Right ); // axes // x axis (lin) LinearAxis linx = (LinearAxis) plotSurface.XAxis2; linx.WorldMin = xmin; linx.WorldMax = xmax; linx.AxisColor = Color.Blue; linx.LabelColor = Color.Blue; linx.TickTextColor = Color.Blue; linx.Label = "x"; plotSurface.XAxis2 = linx; // y axis (lin) LinearAxis liny = (LinearAxis) plotSurface.YAxis2; liny.WorldMin = ymin; liny.WorldMax = ymax; liny.AxisColor = Color.Blue; liny.LabelColor = Color.Blue; liny.TickTextColor = Color.Blue; liny.Label = "x^2"; plotSurface.YAxis2 = liny; plotSurface.Title = "x^2 plotted with log(red)/linear(blue) axes"; plotSurface.XAxis1.LabelOffset = 0; plotSurface.YAxis1.LabelOffset = 0; plotSurface.Refresh(); }
public void PlotCircular() { string lines = "Circular Example. Demonstrates - * PiAxis, Horizontal and Vertical Lines. * Placement of legend"; infoBox.Text = lines; this.plotSurface.Clear(); plotSurface.Add( new HorizontalLine( 0.0, Color.LightGray ) ); plotSurface.Add( new VerticalLine( 0.0, Color.LightGray ) ); const int N = 400; const double start = -Math.PI * 7.0; const double end = Math.PI * 7.0; double[] xs = new double[N]; double[] ys = new double[N]; for (int i=0; i<N; ++i) { double t = ((double)i*(end - start)/(double)N + start); xs[i] = 0.5 * (t - 2.0 * Math.Sin(t)); ys[i] = 2.0 * (1.0 - 2.0 * Math.Cos(t)); } LinePlot lp = new LinePlot( ys, xs ); lp.Pen = new Pen( Color.DarkBlue, 2.0f ); lp.Label = "Circular Line"; // no legend, but still useful for copy data to clipboard. plotSurface.Add( lp ); plotSurface.XAxis1 = new PiAxis( plotSurface.XAxis1 ); plotSurface.Legend = new Legend(); plotSurface.Legend.AttachTo(PlotSurface2D.XAxisPosition.Bottom, PlotSurface2D.YAxisPosition.Right); plotSurface.Legend.HorizontalEdgePlacement = Legend.Placement.Inside; plotSurface.Legend.VerticalEdgePlacement = Legend.Placement.Inside; plotSurface.Legend.XOffset = 0; plotSurface.Legend.YOffset = 0; plotSurface.Refresh(); }
public void PlotGaussian() { string lines = "Gaussian Example. Demonstrates - * HistogramPlot and LinePlot."; infoBox.Text = lines; plotSurface.Clear(); System.Random r = new Random(); int len = 35; double[] a = new double[len]; double[] b = new double[len]; for (int i=0; i<len; ++i) { int j = len-1-i; a[i] = (double)Math.Exp(-(double)(i-len/2)*(double)(i-len/2)/50.0f); b[i] = a[i] + (r.Next(10)/50.0f)-0.05f; if (b[i] < 0.0f) { b[i] = 0; } } HistogramPlot sp = new HistogramPlot(); sp.DataSource = b; sp.Pen = new Pen(Color.DarkBlue); sp.Filled = true; sp.RectangleBrush = new RectangleBrushes.HorizontalCenterFade( Color.Lavender, Color.Gold ); sp.BaseWidth = 0.5f; sp.Label = "Random Data"; LinePlot lp = new LinePlot(); lp.DataSource = a; lp.Pen = new Pen( Color.Blue, 3.0f ); lp.Label = "Gaussian Function"; plotSurface.Add( sp ); plotSurface.Add( lp ); plotSurface.Legend = new Legend(); plotSurface.YAxis1.WorldMin = 0.0f; plotSurface.Title = "Histogram Plot"; plotSurface.XAxis1.LabelOffset = 0; plotSurface.YAxis1.LabelOffset = 0; plotSurface.Refresh(); }
void PlotDataSet() { string lines = "Stock Data Example. Demonstrates - * CandlePlot, FilledRegion, LinePlot and ArrowItem IDrawables * DateTime axes * A few plot interactions. Try (a) dragging the axes (b) dragging the plot surface."; infoBox.Text = lines; plotSurface.Clear(); //plotSurface.DateTimeToolTip = true; // obtain stock information from xml file DataSet ds = new DataSet(); //System.IO.Stream file =Assembly.GetExecutingAssembly().GetManifestResourceStream("ChartProject1.asx_jbh"); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PlotSurface2DDemo)); StringReader reader = new StringReader((String)resources.GetObject("asx_jbh")); ds.ReadXml(reader, System.Data.XmlReadMode.ReadSchema ); DataTable dt = ds.Tables[0]; DataView dv = new DataView( dt ); // create CandlePlot. CandlePlot cp = new CandlePlot(); cp.DataSource = dt; cp.AbscissaData = "Date"; cp.OpenData = "Open"; cp.LowData = "Low"; cp.HighData = "High"; cp.CloseData = "Close"; cp.BearishColor = Color.Red; cp.BullishColor = Color.Green; cp.Style = CandlePlot.Styles.Filled; // calculate 10 day moving average and 2*sd line ArrayList av10 = new ArrayList(); ArrayList sd2_10 = new ArrayList(); ArrayList sd_2_10 = new ArrayList(); ArrayList dates = new ArrayList(); for (int i=0; i<dt.Rows.Count-10; ++i) { float sum = 0.0f; for (int j=0; j<10; ++j) { sum += (float)dt.Rows[i+j]["Close"]; } float average = sum / 10.0f; av10.Add( average ); sum = 0.0f; for (int j=0; j<10; ++j) { sum += ((float)dt.Rows[i+j]["Close"]-average)*((float)dt.Rows[i+j]["Close"]-average); } sum /= 10.0f; sum = 2.0f*(float)Math.Sqrt( sum ); sd2_10.Add( average + sum ); sd_2_10.Add( average - sum ); dates.Add( (DateTime)dt.Rows[i+10]["Date"] ); } // and a line plot of close values. LinePlot av = new LinePlot(); av.OrdinateData = av10; av.AbscissaData = dates; av.Color = Color.LightGray; av.Pen.Width = 2.0f; LinePlot top = new LinePlot(); top.OrdinateData = sd2_10; top.AbscissaData = dates; top.Color = Color.LightSteelBlue; top.Pen.Width = 2.0f; LinePlot bottom = new LinePlot(); bottom.OrdinateData = sd_2_10; bottom.AbscissaData = dates; bottom.Color = Color.LightSteelBlue; bottom.Pen.Width = 2.0f; FilledRegion fr = new FilledRegion( top, bottom ); //fr.RectangleBrush = new RectangleBrushes.Vertical( Color.FloralWhite, Color.GhostWhite ); fr.RectangleBrush = new RectangleBrushes.Vertical( Color.FromArgb(255,255,240), Color.FromArgb(240,255,255) ); plotSurface.Add( fr ); plotSurface.Add( new Grid() ); plotSurface.Add( av ); plotSurface.Add( top ); plotSurface.Add( bottom ); plotSurface.Add( cp ); // now make an arrow... ArrowItem arrow = new ArrowItem( new PointD( ((DateTime)dt.Rows[60]["Date"]).Ticks, 2.28 ), -80, "An interesting flat bit" ); arrow.ArrowColor = Color.DarkBlue; arrow.PhysicalLength = 50; //plotSurface.Add( arrow ); plotSurface.Title = "AU:JBH"; plotSurface.XAxis1.Label = "Date / Time"; plotSurface.XAxis1.WorldMin += plotSurface.XAxis1.WorldLength / 4.0; plotSurface.XAxis1.WorldMax -= plotSurface.XAxis1.WorldLength / 2.0; plotSurface.YAxis1.Label = "Price [$]"; plotSurface.XAxis1 = new TradingDateTimeAxis( plotSurface.XAxis1 ); plotSurface.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.HorizontalDrag()); plotSurface.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalDrag()); plotSurface.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.AxisDrag(true)); // make sure plot surface colors are as we expect - the wave example changes them. plotSurface.PlotBackColor = Color.White; plotSurface.BackColor = System.Drawing.SystemColors.Control; plotSurface.XAxis1.Color = Color.Black; plotSurface.YAxis1.Color = Color.Black; plotSurface.XAxis1.LabelOffset = 0; plotSurface.YAxis1.LabelOffset = 0; 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(); }
public void PlotABC() { string lines = "ABC (logo for australian broadcasting commission) Example. Demonstrates - * How to set the background of a plotsurface as an image. * EqualAspectRatio axis constraint"; infoBox.Text = lines; plotSurface.Clear(); const int size = 200; float [] xs = new float [size]; float [] ys = new float [size]; for (int i=0; i<size; i++) { xs[i] = (float)Math.Sin((double)i/(double)(size-1)*2.0*Math.PI); ys[i] = (float)Math.Cos((double)i/(double)(size-1)*6.0*Math.PI); } LinePlot lp = new LinePlot(); lp.OrdinateData = ys; lp.AbscissaData = xs; Pen linePen = new Pen( Color.Yellow, 5.0f ); lp.Pen = linePen; plotSurface.Add(lp); plotSurface.Title = "AxisConstraint.EqualScaling in action..."; System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PlotSurface2DDemo)); Bitmap map = (Bitmap)resources.GetObject("pattern01"); plotSurface.PlotBackImage = map; plotSurface.AddAxesConstraint( new AxesConstraint.AspectRatio( 1.0, PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Left ) ); plotSurface.XAxis1.WorldMin = plotSurface.YAxis1.WorldMin; plotSurface.XAxis1.WorldMax = plotSurface.YAxis1.WorldMax; plotSurface.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.MouseWheelZoom()); // make sure plot surface colors are as we expect - the wave example changes them. //plotSurface.PlotBackColor = Color.White; plotSurface.BackColor = System.Drawing.SystemColors.Control; plotSurface.XAxis1.Color = Color.Black; plotSurface.YAxis1.Color = Color.Black; plotSurface.XAxis1.LabelOffset = 0; plotSurface.YAxis1.LabelOffset = 0; plotSurface.Refresh(); }
public void PlotWavelet() { string lines = "Wavelet Example. Demonstrates - * Reversing axes, setting number of tick marks on axis explicitly."; infoBox.Text = lines; this.plotSurface.Clear(); // Create a new line plot from array data via the ArrayAdapter class. LinePlot lp = new LinePlot(); lp.DataSource = makeDaub(256); lp.Color = Color.Green; lp.Label = "Daubechies Wavelet"; // no legend, but still useful for copy data to clipboard. Grid myGrid = new Grid(); myGrid.VerticalGridType = Grid.GridType.Fine; myGrid.HorizontalGridType = Grid.GridType.Coarse; this.plotSurface.Add(myGrid); // And add it to the plot surface this.plotSurface.Add( lp ); this.plotSurface.Title = "Reversed / Upside down Daubechies Wavelet"; // Ok, the above will produce a decent default plot, but we would like to change // some of the Y Axis details. First, we'd like lots of small ticks (10) between // large tick values. Secondly, we'd like to draw a grid for the Y values. To do // this, we create a new LinearAxis (we could also use Label, Log etc). Rather than // starting from scratch, we use the constructor that takes an existing axis and // clones it (values in the superclass Axis only are cloned). PlotSurface2D // automatically determines a suitable axis when we add plots to it (merging // current requirements with old requirements), and we use this as our starting // point. Because we didn't specify which Y Axis we are using when we added the // above line plot (there is one on the left - YAxis1 and one on the right - YAxis2) // PlotSurface2D.Add assumed we were using YAxis1. So, we create a new axis based on // YAxis1, update the details we want, then set the YAxis1 to be our updated one. LinearAxis myAxis = new LinearAxis( this.plotSurface.YAxis1 ); myAxis.NumberOfSmallTicks = 2; this.plotSurface.YAxis1 = myAxis; // We would also like to modify the way in which the X Axis is printed. This time, // we'll just modify the relevant PlotSurface2D Axis directly. this.plotSurface.XAxis1.WorldMax = 100.0f; this.plotSurface.PlotBackColor = Color.OldLace; this.plotSurface.XAxis1.Reversed = true; this.plotSurface.YAxis1.Reversed = true; // Force a re-draw of the control. this.plotSurface.Refresh(); }
public void PlotTest() { plotSurface.Clear(); // can plot different types. ArrayList l = new ArrayList(); l.Add( (int)2 ); l.Add( (double)1.0 ); l.Add( (float)3.0 ); l.Add( (int)5.0 ); LinePlot lp1 = new LinePlot( new double[] {4.0, 3.0, 5.0, 8.0} ); lp1.Pen = new Pen( Color.LightBlue ); lp1.Pen.Width = 2.0f; //lp.AbscissaData = new StartStep( 0.0, 2.0 ); LinePlot lp2 = new LinePlot( new double[] {2.0, 1.0, 4.0, 5.0} ); lp2.Pen = new Pen( Color.LightBlue ); lp2.Pen.Width = 2.0f; FilledRegion fr = new FilledRegion( lp1, lp2 ); plotSurface.Add(fr); plotSurface.Add( new Grid() ); plotSurface.Add(lp1); plotSurface.Add(lp2); ArrowItem a = new ArrowItem( new PointD( 2, 4 ), -50.0f, "Arrow" ); a.HeadOffset = 5; a.ArrowColor = Color.Red; a.TextColor = Color.Purple; plotSurface.Add( a ); MarkerItem m = new MarkerItem( new Marker( Marker.MarkerType.TriangleDown, 8, Color.ForestGreen ), 1.38, 2.9 ); plotSurface.Add( m ); plotSurface.XAxis1.TicksCrossAxis = true; ((LinearAxis)plotSurface.XAxis1).LargeTickValue = -4.1; ((LinearAxis)plotSurface.XAxis1).AutoScaleText = true; ((LinearAxis)plotSurface.XAxis1).TicksIndependentOfPhysicalExtent = true; //plotSurface.XAxis1.Label = "Hello world"; plotSurface.XAxis1.LabelOffset = 0; plotSurface.YAxis1.LabelOffset = 0; plotSurface.Refresh(); /* plotSurface.AutoScaleTitle = false; plotSurface.AutoScaleAutoGeneratedAxes = true; plotSurface.Title = "My Title"; double[] a = { 0, 2, 1, 4, double.NaN, double.NaN, 5, 8, 7, 9 }; LinePlot lp = new LinePlot(); lp.DataSource = a; lp.Label = "My Label"; plotSurface.Add( lp ); plotSurface.Legend = new Legend(); plotSurface.Legend.AutoScaleText = false; plotSurface.Legend.NeverShiftAxes = true; plotSurface.Legend.HorizontalEdgePlacement = Legend.Placement.Inside; plotSurface.Legend.VerticalEdgePlacement = Legend.Placement.Inside; plotSurface.Legend.XOffset = -10; plotSurface.Legend.YOffset = 10; //plotSurface.AddAxesConstraint( new AxesConstraint.EqualSpacing() ); ((LinearAxis)plotSurface.XAxis1).Offset = 10.0; ((LinearAxis)plotSurface.XAxis1).Scale = 27.0; //((LinearAxis)plotSurface.XAxis1).TicksIndependentOfPhysicalExtent = true; //((LinearAxis)plotSurface.YAxis1).TicksIndependentOfPhysicalExtent = true; AxesConstraint.AxisPosition c1 = new xuzhenzhen.com.chart.AxesConstraint.AxisPosition( PlotSurface2D.YAxisPosition.Left, 100.0f ); AxesConstraint.AspectRatio c2 = new AxesConstraint.AspectRatio( 5.0f, PlotSurface2D.YAxisPosition.Left ); plotSurface.AddAxesConstraint( c1 ); plotSurface.AddAxesConstraint( c2 ); plotSurface.Refresh(); */ }
public void InitDataToChart() { //清空 chart1.Clear(); chart2.Clear(); chart3.Clear(); //垂直线 vline = new VerticalLine(0, Color.Blue); //图例 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 = 4; //网格 grid = new Grid(); grid.HorizontalGridType = Grid.GridType.Fine; grid.VerticalGridType = Grid.GridType.Fine; grid.MajorGridPen.Color = Color.Silver; grid.MinorGridPen.Color = Color.Silver; /////区域着色//////// fill = new FilledRegion(new VerticalLine(-1), new VerticalLine(8)); fill.Brush = new SolidBrush(Color.FromArgb(250, 218, 169)); ///////////////////////////////////////////// //直线图 sysPlot = new LinePlot(); sysPlot.OrdinateData = sysList; sysPlot.AbscissaData = timeList; sysPlot.Color = Color.RoyalBlue; sysPlot.Pen.Width = 2.0f; sysPlot.Label = "SYS"; diaPlot = new LinePlot(); diaPlot.OrdinateData = diaList; diaPlot.AbscissaData = timeList; diaPlot.Color = Color.OrangeRed; diaPlot.Pen.Width = 2.0f; diaPlot.Label = "DIA"; mapPlot = new LinePlot(); mapPlot.OrdinateData = mapList; mapPlot.AbscissaData = timeList; mapPlot.Color = Color.Chartreuse; mapPlot.Pen.Width = 2.0f; mapPlot.Label = "MAP"; hrPlot = new LinePlot(); hrPlot.OrdinateData = hrList; hrPlot.AbscissaData = timeList; hrPlot.Color = Color.DarkSlateBlue; hrPlot.Pen.Width = 2.0f; sys_hrPlot = new LinePlot(); sys_hrPlot.OrdinateData = sys_hrList; sys_hrPlot.AbscissaData = timeList; sys_hrPlot.Color = Color.Green; sys_hrPlot.Pen.Width = 2.0f; //水平线 hline1 = new HorizontalLine(70, Color.Gray); hline2 = new HorizontalLine(90, Color.Gray); hline3 = new HorizontalLine(120, Color.Gray); hline4 = new HorizontalLine(140, Color.Gray); /////////////////////// chart1.Add(fill); chart1.Add(grid); chart1.Add(sysPlot); chart1.Add(diaPlot); chart1.Add(mapPlot); chart1.Add(hline1); chart1.Add(hline2); chart1.Add(hline3); chart1.Add(hline4); chart1.Add(vline); chart1.XAxis1.HideTickText = true; chart1.YAxis1.Label = "血压:mmHg"; chart1.YAxis1.LabelOffsetAbsolute = true; chart1.YAxis1.WorldMin = chart1.YAxis1.WorldMin - 20; chart1.YAxis1.WorldMax = chart1.YAxis1.WorldMax + 20; chart1.Padding = 5; chart1.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.HorizontalDrag()); chart1.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalDrag()); chart1.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalGuideline()); chart1.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60)); chart1.InteractionOccured += new xuzhenzhen.com.chart.Windows.PlotSurface2D.InteractionHandler(chart1_InteractionOccured); chart1.PlotBackColor = Color.White; chart1.BackColor = System.Drawing.SystemColors.Control; chart1.XAxis1.Color = Color.Black; chart1.YAxis1.Color = Color.Black; chart1.Legend = legend; chart1.LegendZOrder = 1; chart1.Refresh(); /////////////////////////// chart2.Add(fill); chart2.Add(grid); chart2.Add(hrPlot); chart2.Add(vline); chart2.XAxis1.HideTickText = true; chart2.YAxis1.Label = "心率:BPM"; chart2.YAxis1.LabelOffsetAbsolute = true; chart2.Padding = 5; chart2.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60)); chart2.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.HorizontalDrag()); chart2.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalDrag()); chart2.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalGuideline()); chart2.InteractionOccured += new xuzhenzhen.com.chart.Windows.PlotSurface2D.InteractionHandler(chart2_InteractionOccured); chart2.PlotBackColor = Color.White; chart2.BackColor = System.Drawing.SystemColors.Control; chart2.XAxis1.Color = Color.Black; chart2.YAxis1.Color = Color.Black; chart2.Refresh(); /////////////////////////// chart3.Add(fill); chart3.Add(grid); chart3.Add(sys_hrPlot); chart3.Add(vline); LabelAxis axis = new LabelAxis(chart3.XAxis1); int tick = 1; if (chart2.XAxis1.WorldMax - chart2.XAxis1.WorldMin > 30) tick = 2; for (int i = (int)chart2.XAxis1.WorldMin; i <= chart2.XAxis1.WorldMax; i+=tick) { int j = i % 24; if (j < 0) j += 24; axis.AddLabel(Convert.ToString(j), i); } chart3.XAxis1 = axis; chart3.XAxis1.Label = "Time:Hour"; chart3.YAxis1.Label = "SYS*PR/100"; chart3.YAxis1.LabelOffsetAbsolute = true; chart3.Padding = 5; chart3.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60)); chart3.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.HorizontalDrag()); chart3.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalDrag()); chart3.AddInteraction(new xuzhenzhen.com.chart.Windows.PlotSurface2D.Interactions.VerticalGuideline()); chart3.InteractionOccured += new xuzhenzhen.com.chart.Windows.PlotSurface2D.InteractionHandler(chart3_InteractionOccured); chart3.PlotBackColor = Color.White; chart3.BackColor = System.Drawing.SystemColors.Control; chart3.XAxis1.Color = Color.Black; chart3.YAxis1.Color = Color.Black; chart3.Refresh(); SetStatusNow(); }
/// <summary> /// Constructor /// </summary> /// <param name="lp1">LinePlot that provides bounds to filled region [upper or lower]</param> /// <param name="lp2">LinePlot that provides bounds to filled region [upper or lower]</param> /// <remarks>TODO: make this work with other plot types.</remarks> public FilledRegion( LinePlot lp1, LinePlot lp2 ) { lp1_ = lp1; lp2_ = lp2; }