protected override void OnLoad(EventArgs e) { base.OnLoad(e); m_PlotSurface2D = new PlotSurface2D(); m_PlotSurface2D.Clear(); Example_NPlot_Tour. #if WINDOWS_PHONE_7 || WINDOWS_PHONE_71 PlotParticles #else PlotDataSet //PlotWave #endif (m_PlotSurface2D); m_PlotSurface2D.TitleColor = plotSurface_Label_Default; m_PlotSurface2D.XAxis1.AxisColor = plotSurface_AxisColor_Default; m_PlotSurface2D.XAxis1.TickTextColor = plotSurface_TickTextColor_Default; m_PlotSurface2D.XAxis1.LabelColor = plotSurface_Label_Default; m_PlotSurface2D.YAxis1.AxisColor = plotSurface_AxisColor_Default; m_PlotSurface2D.YAxis1.TickTextColor = plotSurface_TickTextColor_Default; m_PlotSurface2D.YAxis1.LabelColor = plotSurface_Label_Default; m_NPlotBitmap = new NPlotBitmap(m_PlotSurface2D); }
internal static void ToDraw(int[] time, double[] valEntry, double[] valAlgo, TypeAction ta, TypeMeasure tm) { _npSurface.Clear(); _npSurface.Title = $"{tm} : {ta}"; _npSurface.BackColor = Color.White; NPlot.Grid grid = new NPlot.Grid(); _npSurface.Add(grid, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left); if (tm == TypeMeasure.Distance) { NPlot.LinePlot plot = new NPlot.LinePlot(); plot.AbscissaData = time; plot.DataSource = valAlgo; plot.Label = "Algorithm"; plot.Color = Color.Blue; _npSurface.Add(plot, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left); } else { NPlot.LinePlot plotAlgo = new NPlot.LinePlot(); NPlot.LinePlot plotEntry = new NPlot.LinePlot(); plotAlgo.AbscissaData = time; plotAlgo.DataSource = valAlgo; plotAlgo.Label = "Algorithm"; plotAlgo.Color = Color.Blue; _npSurface.Add(plotAlgo, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left); plotEntry.AbscissaData = time; plotEntry.DataSource = valEntry; plotEntry.Label = "Entry"; plotEntry.Color = Color.Red; _npSurface.Add(plotEntry, NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left); } _npSurface.XAxis1.Label = "Time"; _npSurface.XAxis1.NumberFormat = "{0:##0}"; _npSurface.XAxis1.LabelFont = AxisFont; _npSurface.XAxis1.TickTextFont = TickFont; _npSurface.YAxis1.Label = $"{tm}"; _npSurface.YAxis1.NumberFormat = "{0:##0.0}"; _npSurface.YAxis1.LabelFont = AxisFont; _npSurface.YAxis1.TickTextFont = TickFont; NPlot.Legend npLegend = new NPlot.Legend(); npLegend.AttachTo(NPlot.PlotSurface2D.XAxisPosition.Top, NPlot.PlotSurface2D.YAxisPosition.Right); npLegend.VerticalEdgePlacement = NPlot.Legend.Placement.Inside; npLegend.HorizontalEdgePlacement = NPlot.Legend.Placement.Outside; npLegend.BorderStyle = NPlot.LegendBase.BorderType.Line; _npSurface.Legend = npLegend; _npSurface.Refresh(); try { if (!Directory.Exists(Path)) { DirectoryInfo di = Directory.CreateDirectory(Path); Console.WriteLine("The directory was created successfully at {0}.", Directory.GetCreationTime(Path)); } var files = Directory.GetFiles($"{Path}/", $"*plot-{ta}-{tm}*.png"); _npSurface.Bitmap.Save($"{Path}/plot-{ta}-{tm}-{files.Length}.png"); } catch (Exception e) { Console.WriteLine("The process failed: {0}", e.ToString()); } }
public static void PlotDataSet(PlotSurface2D plotSurface) { plotSurface.Clear(); //plotSurface.DateTimeToolTip = true; // obtain stock information from xml file DataSet ds = new DataSet(); System.IO.Stream file = Alt.IO.VirtualFile.OpenRead("AltData/NPlot/asx_jbh.xml"); ds.ReadXml(file, XmlReadMode.ReadSchema); DataTable dt = ds.Tables[0]; //NoNeed 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 = Alt.Sketch.Color.Red; cp.BullishColor = Alt.Sketch.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 = Alt.Sketch.Color.LightGray; av.Pen.Width = 2.0f; LinePlot top = new LinePlot(); top.OrdinateData = sd2_10; top.AbscissaData = dates; top.Color = Alt.Sketch.Color.LightSteelBlue; top.Pen.Width = 2.0f; LinePlot bottom = new LinePlot(); bottom.OrdinateData = sd_2_10; bottom.AbscissaData = dates; bottom.Color = Alt.Sketch.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(Alt.Sketch.Color.FromArgb(255, 255, 240), Alt.Sketch.Color.FromArgb(240, 255, 255)); plotSurface.SmoothingMode = 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 = Alt.Sketch.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); }