public void CreatePlot(InteractivePlotSurface2D plotSurface) { plotSurface.Clear(); //plotSurface.DateTimeToolTip = true; // obtain stock information from xml file DataSet ds = new DataSet(); System.IO.Stream file = Assembly.GetExecutingAssembly().GetManifestResourceStream("DemoLib.Resources.asx_jbh.xml"); ds.ReadXml(file, 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.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 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 PlotDrag(true, true)); plotSurface.AddInteraction(new AxisDrag()); // make sure plot surface colors are as we expect - the wave example changes them. plotSurface.PlotBackColor = Color.White; plotSurface.XAxis1.Color = Color.Black; plotSurface.YAxis1.Color = Color.Black; plotSurface.Refresh(); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { 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.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 Florence.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(); */ }