public void InitCandle() { /////////蠟燭圖/////////// CP.BullishColor = Color.Red; CP.BearishColor = Color.Green; CP.Style = CandlePlot.Styles.Filled; int[] opens = { 1, 2, 1, 2, 1, 3, 50 }; int[] closes = { 2, 2, 2, 1, 2, 1, 99 }; int[] lows = { 1, 1, 1, 1, 1, 1, 40 }; int[] highs = { 3, 2, 3, 3, 3, 4, 110 }; int[] times = { 100, 200, 300, 400, 500, 600, 700 }; CP.CloseData = closes; CP.OpenData = opens; CP.LowData = lows; CP.HighData = highs; CP.AbscissaData = times; CP.Color = Color.Gray; CP.Centered = false; //PS.Add(linePlot); //PS.Add(pointPlot); PS.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag()); PS.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag()); PS.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(true)); }
private void DrawPointPlot(DataTable dt) { #region 1.初始化 volumePS this.volumePS = new NPlot.Windows.PlotSurface2D(); // // volumePS // this.volumePS.AutoScaleAutoGeneratedAxes = false; this.volumePS.AutoScaleTitle = false; this.volumePS.BackColor = System.Drawing.SystemColors.ControlLightLight; this.volumePS.DateTimeToolTip = false; this.volumePS.Legend = null; this.volumePS.LegendZOrder = -1; //this.volumePS.Location = new System.Drawing.Point(70, 636); this.volumePS.Dock = DockStyle.Fill; this.volumePS.Name = "volumePS"; this.volumePS.RightMenu = null; this.volumePS.ShowCoordinates = false; this.volumePS.Size = new System.Drawing.Size(1053, 139); this.volumePS.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; this.volumePS.TabIndex = 3; this.volumePS.Title = ""; this.volumePS.TitleFont = new System.Drawing.Font("Arial", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel); this.volumePS.XAxis1 = null; this.volumePS.XAxis2 = null; this.volumePS.YAxis1 = null; this.volumePS.YAxis2 = null; #endregion /*--============================================volumePS-PointPlot========================================================--*/ #region 3.1 创建PointPlot【pp】. PointPlot pp = new PointPlot(); pp.Marker = new Marker(Marker.MarkerType.Square, 0); pp.Marker.Pen = new Pen(Color.Red, 5.0f); pp.Marker.DropLine = true; pp.DataSource = dt; pp.AbscissaData = "Date"; pp.OrdinateData = "Volume"; #endregion #region 3.2 添加pp到volumePS volumePS.Clear(); volumePS.Add(pp); volumePS.YAxis1.Label = "Volume"; volumePS.YAxis1.LabelOffsetAbsolute = true; volumePS.YAxis1.LabelOffset = 40; volumePS.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60)); volumePS.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(false)); volumePS.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag()); volumePS.InteractionOccured += new NPlot.Windows.PlotSurface2D.InteractionHandler(volumePS_InteractionOccured); volumePS.PreRefresh += new NPlot.Windows.PlotSurface2D.PreRefreshHandler(volumePS_PreRefresh); #endregion }
public static void SetState(NPlot.Windows.PlotSurface2D graph, MouseState mouseState) { switch (mouseState) { case MouseState.Pan: graph.RemoveInteraction(zoomInteraction); graph.AddInteraction(panInteraction); break; case MouseState.Zoom: graph.RemoveInteraction(panInteraction); graph.AddInteraction(zoomInteraction); break; case MouseState.Pointer: graph.RemoveInteraction(zoomInteraction); graph.RemoveInteraction(panInteraction); break; } }
private void DrawCandlePlot(DataTable dt) { #region 1.初始化costPS this.costPS = new NPlot.Windows.PlotSurface2D(); this.costPS.AutoScaleAutoGeneratedAxes = false; this.costPS.AutoScaleTitle = false; this.costPS.BackColor = System.Drawing.SystemColors.ControlLightLight; this.costPS.DateTimeToolTip = false; this.costPS.Legend = null; this.costPS.LegendZOrder = -1; //this.costPS.Location = new System.Drawing.Point(70, 52); this.costPS.Dock = DockStyle.Fill; this.costPS.Size = new System.Drawing.Size(1053, 557); this.costPS.Name = "costPS"; this.costPS.RightMenu = null; this.costPS.ShowCoordinates = false; this.costPS.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; this.costPS.TabIndex = 2; this.costPS.Title = ""; this.costPS.TitleFont = new System.Drawing.Font("Arial", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel); this.costPS.XAxis1 = null; this.costPS.XAxis2 = null; this.costPS.YAxis1 = null; this.costPS.YAxis2 = null; #endregion /*--===========================================costPS-CandlePlot=========================================================--*/ #region 2.1 创建 CandlePlot【cp】. 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.White; //方框颜色 cp.BullishColor = Color.Green; //方框颜色 cp.Style = CandlePlot.Styles.Filled; #endregion #region 2.2 添加cp到costPS costPS.Clear(); costPS.DateTimeToolTip = true; costPS.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; costPS.Add(new Grid()); costPS.Add(cp); // costPS.Title = "AU:JBH";//标题 // costPS.YAxis1.Label = "Price [$]"; //左侧标题 costPS.YAxis1.LabelOffset = 40; costPS.YAxis1.LabelOffsetAbsolute = true; costPS.XAxis1.HideTickText = true; costPS.YAxis1.HideTickText = true;//是否隐藏垂直刻度线标尺 costPS.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag()); costPS.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag()); costPS.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(false)); costPS.InteractionOccured += new NPlot.Windows.PlotSurface2D.InteractionHandler(costPS_InteractionOccured); costPS.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60)); this.costPS.RightMenu = new ReducedContextMenu(); #endregion }
private void PlotChart(QueryResultsEventArgs e, PlotSurface2D plot, List <Guid> signals, bool cacheAxis) { if (cacheAxis) { maxX = plot.XAxis1.WorldMax; minX = plot.XAxis1.WorldMin; maxY = plot.YAxis1.WorldMax; minY = plot.YAxis1.WorldMin; foreach (IDrawable drawing in plot.Drawables.ToArray()) { plot.Remove(drawing, false); } ColorWheel.Reset(); foreach (Guid freq in signals) { SignalDataBase data = e.Results[freq]; List <double> y = new List <double>(data.Count); List <double> x = new List <double>(data.Count); for (int i = 0; i < data.Count; i++) { data.GetData(i, out ulong time, out double value); x.Add(time); y.Add(value); } LinePlot lines = new LinePlot(y, x); lines.Pen = ColorWheel.GetPen(); plot.Add(lines); } plot.XAxis1.WorldMax = maxX; plot.XAxis1.WorldMin = minX; plot.YAxis1.WorldMax = maxY; plot.YAxis1.WorldMin = minY; plot.Refresh(); } else { plot.Clear(); plot.AddInteraction(new PlotSurface2D.Interactions.HorizontalDrag()); plot.AddInteraction(new PlotSurface2D.Interactions.VerticalDrag()); plot.AddInteraction(new PlotSurface2D.Interactions.AxisDrag(false)); ColorWheel.Reset(); foreach (Guid freq in signals) { SignalDataBase data = e.Results[freq]; List <double> y = new List <double>(data.Count); List <double> x = new List <double>(data.Count); for (int i = 0; i < data.Count; i++) { data.GetData(i, out ulong time, out double value); x.Add(time); y.Add(value); } LinePlot lines = new LinePlot(y, x); lines.Pen = ColorWheel.GetPen(); plot.Add(lines); } plot.Refresh(); } }
public void InitSystemPlot() { try { plotSurface.Clear(); this.plotSurface.RightMenu = PlotSurface2D.DefaultContextMenu; plotSurface.Add(lineAvail); plotSurface.Add(lineUsage); plotSurface.PlotBackColor = plotSurface.BackColor; plotSurface.SmoothingMode = SmoothingMode.AntiAlias; plotSurface.Title = "CPU Power - Availability & Usage"; //plotSurface.TitleFont = new Font(new FontFamily("Microsoft Sans Serif" ), 9.75f, FontStyle.Bold); plotSurface.XAxis1.WorldMin = -60.0f; plotSurface.XAxis1.WorldMax = 0.0f; plotSurface.XAxis1.Label = "Seconds"; //plotSurface.XAxis1.LabelFont = new Font(new FontFamily("Microsoft Sans Serif" ), 9.75f, FontStyle.Bold); //plotSurface.XAxis1.TickTextFont = new Font(new FontFamily("Microsoft Sans Serif" ), 9.75f, FontStyle.Bold); plotSurface.YAxis1.WorldMin = 0.0; plotSurface.YAxis1.WorldMax = 100.0; plotSurface.YAxis1.Label = "Power [%]"; //plotSurface.YAxis1.LabelFont = new Font(new FontFamily("Microsoft Sans Serif" ), 9.75f, FontStyle.Bold); //plotSurface.YAxis1.TickTextFont = new Font(new FontFamily("Microsoft Sans Serif" ), 9.75f, FontStyle.Bold); Grid gridPlotSurface = new Grid(); gridPlotSurface.HorizontalGridType = Grid.GridType.None; gridPlotSurface.VerticalGridType = Grid.GridType.Fine; gridPlotSurface.MajorGridPen.Color = Color.DarkGray; plotSurface.Add(gridPlotSurface); plotSurface.Legend = new Legend(); plotSurface.Legend.NeverShiftAxes = false; plotSurface.Legend.AttachTo(NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left); plotSurface.Legend.HorizontalEdgePlacement = Legend.Placement.Inside; plotSurface.Legend.VerticalEdgePlacement = Legend.Placement.Inside; lineAvail.Label = "usage"; lineAvail.Pen = new Pen(Color.Crimson, 2.0f); lineUsage.Label = "avail"; lineUsage.Pen = new Pen(Color.SteelBlue, 2.0f); plotSurface.AddInteraction(new PlotSurface2D.Interactions.HorizontalDrag()); plotSurface.AddInteraction(new PlotSurface2D.Interactions.VerticalDrag()); plotSurface.AddInteraction(new PlotSurface2D.Interactions.AxisDrag(true)); plotSurface.PlotBackColor = Color.White; plotSurface.BackColor = SystemColors.Control; plotSurface.XAxis1.Color = Color.Black; plotSurface.YAxis1.Color = Color.Black; plotSurface.Refresh(); } catch (Exception ex) { MessageBox.Show("Couldnot initialize graph. Error: " + ex.Message, "Console Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public FinancialDemo() { // // Required for Windows Form Designer support // InitializeComponent(); costPS.Clear(); costPS.DateTimeToolTip = true; // obtain stock information from xml file DataSet ds = new DataSet(); System.IO.Stream file = Assembly.GetExecutingAssembly().GetManifestResourceStream("NPlotDemo.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; costPS.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; costPS.Add(new Grid()); costPS.Add(cp); costPS.Title = "AU:JBH"; costPS.YAxis1.Label = "Price [$]"; costPS.YAxis1.LabelOffset = 40; costPS.YAxis1.LabelOffsetAbsolute = true; costPS.XAxis1.HideTickText = true; costPS.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag()); costPS.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag()); costPS.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(false)); costPS.InteractionOccured += new NPlot.Windows.PlotSurface2D.InteractionHandler(costPS_InteractionOccured); costPS.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60)); PointPlot pp = new PointPlot(); pp.Marker = new Marker(Marker.MarkerType.Square, 0); pp.Marker.Pen = new Pen(Color.Red, 5.0f); pp.Marker.DropLine = true; pp.DataSource = dt; pp.AbscissaData = "Date"; pp.OrdinateData = "Volume"; volumePS.Add(pp); volumePS.YAxis1.Label = "Volume"; volumePS.YAxis1.LabelOffsetAbsolute = true; volumePS.YAxis1.LabelOffset = 40; volumePS.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60)); volumePS.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(false)); volumePS.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag()); volumePS.InteractionOccured += new NPlot.Windows.PlotSurface2D.InteractionHandler(volumePS_InteractionOccured); volumePS.PreRefresh += new NPlot.Windows.PlotSurface2D.PreRefreshHandler(volumePS_PreRefresh); this.costPS.RightMenu = new ReducedContextMenu(); }
/// <summary> /// 利用雅虎接口获取日K线图 /// </summary> /// <param name="stockNo"></param> /// <returns></returns> public static void GetStockMapDay(string stockNo, NPlot.Windows.PlotSurface2D myPlot) { DataTable dt = CommonFunction.GetStockHistoryInfo(stockNo); for (int i = 0; i < dt.Rows.Count; i++) { if (int.Parse(dt.Rows[i]["Volume"].ToString()) == 0) { dt.Rows.RemoveAt(i); i = 0; } } dt.DefaultView.Sort = " Date asc"; dt = dt.DefaultView.ToTable(); dt.Columns.Add("Date2", typeof(DateTime)); foreach (DataRow dr in dt.Rows) { dr["Date2"] = DateTime.Parse(dr["Date"].ToString()); } myPlot.Clear(); List <double> listOpen = new List <double>(); List <double> listLow = new List <double>(); List <double> listHigh = new List <double>(); List <double> listClose = new List <double>(); ArrayList dates = new ArrayList(); ArrayList closes = new ArrayList(); List <string> listText = new List <string>(); List <int> listCount = new List <int>(); int n = 0; foreach (DataRow dr in dt.Rows) { n++; listCount.Add(n); //if (n == 24) break; listOpen.Add(double.Parse(dr["Open"].ToString())); dates.Add(DateTime.Parse(dr["Date"].ToString())); listHigh.Add(double.Parse(dr["High"].ToString())); listLow.Add(double.Parse(dr["Low"].ToString())); listClose.Add(double.Parse(dr["Adj Close"].ToString())); closes.Add(double.Parse(dr["Adj Close"].ToString())); listText.Add(Math.Round(double.Parse(dr["Adj Close"].ToString()), 2, MidpointRounding.AwayFromZero).ToString()); } ////////网格////////// Grid mygrid = new Grid(); myPlot.Add(mygrid); ///////蜡烛图/////////// CandlePlot cp = new CandlePlot(); cp.DataSource = dt; cp.AbscissaData = "Date2"; cp.OpenData = "Open"; cp.LowData = "Low"; cp.HighData = "High"; cp.CloseData = "Adj Close"; cp.BullishColor = Color.Red; cp.BearishColor = Color.Green; cp.Centered = false; //cp.StickWidth = 3; //cp.Color = Color.DarkBlue; myPlot.Add(cp); LabelPointPlot lp = new LabelPointPlot(); lp.AbscissaData = dates; lp.OrdinateData = listHigh.ToArray(); lp.TextData = listText.ToArray(); lp.LabelTextPosition = LabelPointPlot.LabelPositions.Above; lp.Marker = new Marker(Marker.MarkerType.None, 10); myPlot.Add(lp); myPlot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.MouseWheelZoom()); myPlot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag()); myPlot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag()); myPlot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(true)); myPlot.Title = string.Format("Stcok {0}", stockNo); myPlot.XAxis1.Label = "Date / Time"; myPlot.YAxis1.Label = "Price [$]"; //myPlot.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.XAxisPosition.Bottom, 100)); //////画箭头////////// //ArrowItem a = new ArrowItem(new PointD(2016, 10), 0, "Arrow"); //a.HeadOffset = 0; //a.ArrowColor = Color.Red; //a.TextColor = Color.Purple; //myPlot.Add(a); myPlot.Refresh(); }