public GroupSumPlotSurface(int targetNumber) { TargetNumber = targetNumber; // Set up plot surface linePlot.Pen = new Pen(Color.FromArgb(0xCC, 0xCC, 0xFF), 3); lowMarker.Size = 10; lowMarker.Type = Marker.MarkerType.FilledCircle; lowMarker.Pen = new Pen(Color.FromArgb(0x00, 0x00, 0x66), 3); lowMarker.FillBrush = new SolidBrush(Color.FromArgb(0x66, 0x66, 0xCC)); highMarker.Size = 10; highMarker.Type = Marker.MarkerType.FilledCircle; highMarker.Pen = new Pen(Color.FromArgb(0x66, 0x00, 0x00), 3); highMarker.FillBrush = new SolidBrush(Color.FromArgb(0xCC, 0x66, 0x66)); correctMarker.Size = 10; correctMarker.Type = Marker.MarkerType.FilledCircle; correctMarker.Pen = new Pen(Color.FromArgb(0x00, 0x66, 0x00), 3); correctMarker.FillBrush = new SolidBrush(Color.FromArgb(0x66, 0xCC, 0x66)); pointPlot.Marker = correctMarker; pointPlot.MarkerCallback = new MarkerCallback(pointPlot_MarkerCallback); pointPlot.LabelOffset = 15.0f; pointPlot.LabelPadding = 2.0f; pointPlot.LabelFont = new Font("Arial", 11.0f, FontStyle.Bold); plotSurface.Add(new Grid() { VerticalGridType = Grid.GridType.Coarse, HorizontalGridType = Grid.GridType.Coarse }); plotYAxis.SmallTickSize = 1; plotYAxis.WorldMin = 0; plotYAxis.WorldMax = 100; plotYAxis.TickTextFont = new Font("Arial", 12); plotXAxis.LargeTickStep = 1; plotXAxis.SmallTickSize = 1; plotXAxis.WorldMin = 1; plotXAxis.WorldMax = 10; plotXAxis.TickTextFont = new Font("Arial", 12); plotXAxis.TickTextNextToAxis = false; plotSurface.SmoothingMode = SmoothingMode.HighQuality; plotSurface.YAxis1 = plotYAxis; plotSurface.XAxis1 = plotXAxis; plotSurface.Add(linePlot); plotSurface.Add(pointPlot); linePlot.AbscissaData = null; linePlot.OrdinateData = null; pointPlot.AbscissaData = null; pointPlot.OrdinateData = null; }
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()); } }
internal void AddLine(PlotSurface2D plot, double[] x, double[] y, string name) { ArrayAdapter data = new ArrayAdapter(x,y); Color c= NextColor(); LinePlot line = new LinePlot(data); line.Label = name; Pen p = new Pen(c,2); line.Pen = p; plot.Add(line); }
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); }