public void CreatePlot(InteractivePlotSurface2D plotSurface) { plotSurface.Clear(); // 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]; // 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.StickWidth = 3; cp.Color = Color.DarkBlue; plotSurface.Add(new Grid()); plotSurface.Add(cp); plotSurface.Title = "AU:JBH"; plotSurface.XAxis1.Label = "Date / Time"; plotSurface.YAxis1.Label = "Price [$]"; plotSurface.Refresh(); }
public Form1() { InitializeComponent(); //this.plotSurface2D1.Clear(); plot.Clear(); //清空 int[] opens = { 1, 2, 1, 2, 1, 3 }; //圆柱底坐标 double[] closes = { 2, 2, 2, 1, 2, 1 }; //圆柱顶坐标 float[] lows = { 0, 1, 1, 1, 0, 0 }; //下线坐标 System.Int64[] highs = { 3, 2, 3, 3, 3, 4 }; //上线坐标 int[] times = { 0, 1, 2, 3, 4, 5 }; //X轴位置 CandlePlot cp = new CandlePlot(); cp.CloseData = closes; cp.OpenData = opens; cp.LowData = lows; cp.HighData = highs; cp.AbscissaData = times; plot.Add(cp); plot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.HorizontalDrag()); plot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.VerticalDrag()); plot.AddInteraction(new NPlot.Windows.PlotSurface2D.Interactions.AxisDrag(true)); plot.XAxis1.IncreaseRange(0.1); plot.YAxis1.IncreaseRange(0.1); //缩小到合适大小 plot.Refresh(); }
public void LoadPriceBars(Bookmark <IPriceBar> priceBars) { int maxIndex = priceBars.Count; double[] opens = new double[maxIndex]; double[] highs = new double[maxIndex]; double[] lows = new double[maxIndex]; double[] closes = new double[maxIndex]; double[] times = new double[maxIndex]; for (int i = 0; i < maxIndex; i++) { IPriceBar priceBar = priceBars[i]; opens[i] = priceBar.Open; highs[i] = priceBar.High; lows[i] = priceBar.Low; closes[i] = priceBar.Close; times[i] = i; } CandlePlot cp = new CandlePlot(); cp.OpenData = opens; cp.HighData = highs; cp.LowData = lows; cp.CloseData = closes; cp.AbscissaData = times; plotSurface.Clear(); plotSurface.Add(cp); plotSurface.Refresh(); }
private void button5_Click(object sender, EventArgs e) { ///////蜡烛图/////////// Random rand = new Random(); int[] opens = { rand.Next(1, 10), rand.Next(1, 10) }; double[] closes = { rand.Next(1, 10), rand.Next(1, 10) }; float[] lows = { 1, 1 }; System.Int64[] highs = { rand.Next(10, 13), rand.Next(10, 13) }; int[] times = { timesNext++, timesNext++ }; if (cp_button5 == null) { cp_button5 = new CandlePlot(); cp_button5.CloseData = closes; cp_button5.OpenData = opens; cp_button5.LowData = lows; cp_button5.HighData = highs; cp_button5.AbscissaData = times; this.myPlot.Add(cp_button5); } else { cp_button5.CloseData = closes; cp_button5.OpenData = opens; cp_button5.LowData = lows; cp_button5.HighData = highs; cp_button5.AbscissaData = times; } this.myPlot.Refresh(); }
//读取数据库数据并用蜡烛图表示 private void BtnReadDb_Click(object sender, EventArgs e) { string sql = "select * from stock_000826 where Id < 500"; SqlHelper shr = new SqlHelper(); DataTable dt = shr.Query(sql); CandlePlot cp = new CandlePlot(); cp.DataSource = dt; cp.AbscissaData = "Id"; cp.OpenData = "openPri"; cp.LowData = "lowPri"; cp.HighData = "highPri"; cp.CloseData = "closePri"; cp.Label = "走势图"; /* * SqlDataReader sdr = shr.QueryOperation(sql); * ArrayList arrayStart = new ArrayList(); * ArrayList arrayEnd = new ArrayList(); * ArrayList arrayHigh = new ArrayList(); * ArrayList arrayLow = new ArrayList(); * ArrayList arrayTime = new ArrayList(); * while(sdr.Read()) * { * arrayStart.Add(sdr[5].ToString()); * arrayLow.Add(sdr[4].ToString()); * arrayHigh.Add(sdr[3].ToString()); * arrayEnd.Add(sdr[2].ToString()); * arrayTime.Add(sdr[0]); * } * * Double[] Start = arrayStart.Cast<object>().Select(t => Convert.ToDouble(t)).ToArray(); * Double[] Low = arrayLow.Cast<object>().Select(t => Convert.ToDouble(t)).ToArray(); * Double[] High = arrayHigh.Cast<object>().Select(t => Convert.ToDouble(t)).ToArray(); * Double[] End = arrayEnd.Cast<object>().Select(t => Convert.ToDouble(t)).ToArray(); * int[] Time = arrayTime.Cast<object>().Select(t => Convert.ToInt32(t)).ToArray(); * * CandlePlot cp = new CandlePlot(); * cp.CloseData = End; * cp.OpenData = Start; * cp.LowData = Low; * cp.HighData = High; * cp.AbscissaData = Time; */ plot.Title = "走势图"; plot.CreateGraphics(); try { this.plot.Add(cp); }catch (Exception ex) { throw ex; } panelPlot.Refresh(); }
private void Form1_Load(object sender, EventArgs e) { plot.Clear(); //对象名称为plot // --- Grid Code --- Grid mygrid = new Grid(); mygrid.HorizontalGridType = Grid.GridType.None; mygrid.VerticalGridType = Grid.GridType.Fine; plot.Add(mygrid); plot.Title = "K-line"; //普通线 StepPlot line = new StepPlot(); line.Pen = new Pen(Color.Red, 1); line.OrdinateData = new double[] { 0, 1, 0, 1, 1, 0.5, 1, 1, 1 }; line.HideVerticalSegments = false; plot.Add(line); plot.Refresh(); //蜡烛图 int[] opens = { 1, 2, 1, 2, 1, 3 }; //开始数目 double[] closes = { 2, 2, 2, 1, 2, 1 }; //结束数目 float[] lows = { 1, 1, 1, 1, 1, 1 }; //最高 System.Int64[] highs = { 3, 2, 3, 3, 3, 4 }; //最低 int[] times = { 0, 1, 2, 3, 4, 5 }; //时间 CandlePlot cp = new CandlePlot(); cp.CloseData = closes; cp.OpenData = opens; cp.LowData = lows; cp.HighData = highs; cp.AbscissaData = times; plot2.Title = "蜡烛图"; this.plot2.Add(cp); //水平+垂直 线 plot3.Add(mygrid); HorizontalLine line3 = new HorizontalLine(10); //水平线 VerticalLine line4 = new VerticalLine(10); //垂直线 line3.LengthScale = 2.89f; line4.LengthScale = 0.89f; plot3.Title = "水平+垂直 线"; plot3.Add(line3, 10); plot3.Add(line4, 1); return; }
public PriceAction() { plotSurface = new NPlot.Bitmap.PlotSurface2D(700, 500); string infoText = ""; infoText += "Simple CandlePlot example. Demonstrates - \n"; infoText += " * Setting candle plot datapoints using arrays \n"; infoText += " * Plot Zoom interaction using MouseWheel "; plotSurface.Clear(); FilledRegion fr = new FilledRegion( new VerticalLine(1.2), new VerticalLine(2.4)); fr.Brush = Brushes.BlanchedAlmond; plotSurface.Add(fr); // note that arrays can be of any type you like. int[] opens = { 1, 2, 1, 2, 1, 3 }; double[] closes = { 2, 2, 2, 1, 2, 1 }; float[] lows = { 0, 1, 1, 1, 0, 0 }; System.Int64[] highs = { 3, 2, 3, 3, 3, 4 }; int[] times = { 0, 1, 2, 3, 4, 5 }; CandlePlot cp = new CandlePlot(); cp.CloseData = closes; cp.OpenData = opens; cp.LowData = lows; cp.HighData = highs; cp.AbscissaData = times; plotSurface.Add(cp); HorizontalLine line = new HorizontalLine(1.2); line.LengthScale = 0.89f; plotSurface.Add(line, -10); VerticalLine line2 = new VerticalLine(1.2); line2.LengthScale = 0.89f; plotSurface.Add(line2); plotSurface.AddInteraction(new PlotZoom()); plotSurface.Title = "Line in the Title Number 1\nFollowed by another title line\n and another"; plotSurface.Refresh(); }
public CandlePlotSample() : base() { infoText = ""; infoText += "Simple CandlePlot example. Demonstrates - \n"; infoText += " * Setting candle plot datapoints using arrays \n"; plotCanvas.Clear(); //FilledRegion fr = new FilledRegion (new VerticalLine (1.2), new VerticalLine (2.4)); //fr.Brush = Brushes.BlanchedAlmond; //plotCanvas.Add (fr); // note that arrays can be of any type you like. int[] opens = { 1, 2, 1, 2, 1, 3 }; double[] closes = { 2, 2, 2, 1, 2, 1 }; float[] lows = { 0, 1, 1, 1, 0, 0 }; System.Int64[] highs = { 3, 2, 3, 3, 3, 4 }; int[] times = { 0, 1, 2, 3, 4, 5 }; CandlePlot cp = new CandlePlot(); cp.CloseData = closes; cp.OpenData = opens; cp.LowData = lows; cp.HighData = highs; cp.AbscissaData = times; plotCanvas.Add(cp); HorizontalLine line = new HorizontalLine(1.2); line.LengthScale = 0.89; plotCanvas.Add(line, -10); //VerticalLine line2 = new VerticalLine ( 1.2 ); //line2.LengthScale = 0.89; //plotCanvas.Add (line2); plotCanvas.Title = "Line in the Title Number 1\nFollowed by another title line\n and another"; plotCanvas.Redraw(); plotCanvas.Legend = new Legend( ); plotCanvas.LegendZOrder = 1; // default zorder for adding idrawables is 0, so this puts legend on top. PackStart(plotCanvas.Canvas, true); Label la = new Label(infoText); PackStart(la); }
public void CreatePlot(InteractivePlotSurface2D plotSurface) { plotSurface.Clear(); FilledRegion fr = new FilledRegion( new VerticalLine(1.2), new VerticalLine(2.4)); fr.Brush = Brushes.BlanchedAlmond; plotSurface.Add(fr); // note that arrays can be of any type you like. int[] opens = { 1, 2, 1, 2, 1, 3 }; double[] closes = { 2, 2, 2, 1, 2, 1 }; float[] lows = { 0, 1, 1, 1, 0, 0 }; System.Int64[] highs = { 3, 2, 3, 3, 3, 4 }; int[] times = { 0, 1, 2, 3, 4, 5 }; CandlePlot cp = new CandlePlot(); cp.CloseData = closes; cp.OpenData = opens; cp.LowData = lows; cp.HighData = highs; cp.AbscissaData = times; plotSurface.Add(cp); HorizontalLine line = new HorizontalLine(1.2); line.LengthScale = 0.89f; plotSurface.Add(line, -10); VerticalLine line2 = new VerticalLine(1.2); line2.LengthScale = 0.89f; plotSurface.Add(line2); plotSurface.AddInteraction(new PlotZoom()); plotSurface.Title = "Line in the Title Number 1\nFollowed by another title line\n and another"; plotSurface.Refresh(); }
private void button1_Click(object sender, EventArgs e) { this.myPlot.Clear(); ////////网格////////// Grid mygrid = new Grid(); mygrid.HorizontalGridType = Grid.GridType.Fine; mygrid.VerticalGridType = Grid.GridType.Fine; this.myPlot.Add(mygrid); ///////水平线////////// HorizontalLine line = new HorizontalLine(10); line.LengthScale = 2.89f; //line.OrdinateValue = 2; this.myPlot.Add(line, 10); ///////垂直线/////////// VerticalLine line2 = new VerticalLine(10); line2.LengthScale = 0.89f; this.myPlot.Add(line2); ///////蜡烛图/////////// int[] opens = { 1, 2, 1, 2, 1, 3 }; double[] closes = { 2, 2, 2, 1, 2, 1 }; float[] lows = { 1, 1, 1, 1, 1, 1 }; System.Int64[] highs = { 3, 2, 3, 3, 3, 4 }; int[] times = { 0, 1, 2, 3, 4, 5 }; CandlePlot cp = new CandlePlot(); cp.CloseData = closes; cp.OpenData = opens; cp.LowData = lows; cp.HighData = highs; cp.AbscissaData = times; cp.BullishColor = Color.Red; cp.BearishColor = Color.Green; this.myPlot.Add(cp); this.myPlot.Refresh(); }
private void Btnrefesh_Click(object sender, EventArgs e) { int[] opens = { 1, 2 }; //开始数目 double[] closes = { 2.2, 2.003 }; //结束数目 float[] lows = { 1, 1 }; //最高 System.Int64[] highs = { 3, 2 }; //最低 int[] times = { 0, 1, 2, 3, 4, 5 }; //时间 CandlePlot cp = new CandlePlot { CloseData = closes, OpenData = opens, LowData = lows, HighData = highs, AbscissaData = times }; plot.Title = "蜡烛图"; this.plot.Add(cp); panelPlot.Refresh(); }
/////////K线图绘制////////// public void PlotCandle(CandlePlot cp, List <DateTime> dates, trader.KLine.TimeFrame timeframe) { try { myPlot.Clear(); // --- Grid Code --- Grid mygrid = new Grid(); mygrid.HorizontalGridType = Grid.GridType.Fine; mygrid.VerticalGridType = Grid.GridType.Fine; myPlot.Add(mygrid); cp.BullishColor = Color.Red; //cp.Color = Color.Black; cp.Centered = false; cp.BearishColor = Color.Green; cp.Style = CandlePlot.Styles.Filled; this.myPlot.Add(cp); //////这里需要先添加图形后设置坐标轴 /////字符坐标轴加入后会隐藏原来的x坐标轴 LabelAxis la1 = new LabelAxis(this.myPlot.XAxis1); for (int i = 0; i < dates.Count; i++) { switch (timeframe) { case trader.KLine.TimeFrame.M1: if (Math.IEEERemainder(i, 30) == 0) { la1.AddLabel(dates[i].ToShortTimeString() + @" " + dates[i].ToShortDateString(), i); } break; case trader.KLine.TimeFrame.M5: if (Math.IEEERemainder(i, 12) == 0) { la1.AddLabel(dates[i].ToShortTimeString() + @" " + dates[i].ToShortDateString(), i + 00); } break; default: if (Math.IEEERemainder(i, 5) == 0) { la1.AddLabel(dates[i].ToShortTimeString() + @" " + dates[i].ToShortDateString(), i + 00); } break; } } //la1.Label = "时间"; la1.TickTextFont = new Font("Courier New", 8); la1.TicksBetweenText = false; this.myPlot.XAxis1 = la1; //////让日期斜45度。 //myPlot.XAxis1.TicksLabelAngle = 45; myPlot.Refresh(); } catch (Exception e) { //Console.WriteLine("{0} Exception caught.", e); //MessageBox.Show(e.ToString()); } }
public TradingSample() : base() { infoText = ""; infoText += "Stock Dataset Sample. Demonstrates - \n"; infoText += " * CandlePlot, FilledRegion, LinePlot and ArrowItem IDrawables \n"; infoText += " * DateTime axes \n"; infoText += " * Horizontal Drag Interaction - try dragging the plot surface \n"; infoText += " * Axis Drag Interaction - try dragging in the horizontal and vertical Axis areas"; plotCanvas.Clear(); // [NOTIMP] plotCanvas.DateTimeToolTip = true; // obtain stock information from xml file DataSet ds = new DataSet(); System.IO.Stream file = Assembly.GetExecutingAssembly().GetManifestResourceStream("Samples.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 = Colors.Red; cp.BullishColor = Colors.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.LineColor = Colors.DarkGray; av.LineWidth = 2.0; LinePlot top = new LinePlot(); top.OrdinateData = sd2_10; top.AbscissaData = dates; top.LineColor = Colors.LightBlue; top.LineWidth = 2.0; LinePlot bottom = new LinePlot(); bottom.OrdinateData = sd_2_10; bottom.AbscissaData = dates; bottom.LineColor = Colors.LightBlue; bottom.LineWidth = 2.0; FilledRegion fr = new FilledRegion(top, bottom); fr.FillColor = Colors.LightGreen; // Note: order of adding FilledRegion, Plots, etc is important for visibility plotCanvas.Add(fr); plotCanvas.Add(new Grid()); plotCanvas.Add(av); plotCanvas.Add(top); plotCanvas.Add(bottom); plotCanvas.Add(cp); // now make an arrow... ArrowItem arrow = new ArrowItem(new Point(((DateTime)dt.Rows[60]["Date"]).Ticks, 2.28), -80, "An interesting flat bit"); arrow.ArrowColor = Colors.DarkBlue; arrow.PhysicalLength = 50; plotCanvas.Add(arrow); plotCanvas.Title = "Stock Prices"; plotCanvas.XAxis1.Label = "Date / Time"; plotCanvas.XAxis1.WorldMin += plotCanvas.XAxis1.WorldLength / 4.0; plotCanvas.XAxis1.WorldMax -= plotCanvas.XAxis1.WorldLength / 2.0; plotCanvas.YAxis1.Label = "Price [$]"; plotCanvas.XAxis1 = new TradingDateTimeAxis(plotCanvas.XAxis1); plotCanvas.PlotBackColor = Colors.White; plotCanvas.XAxis1.LineColor = Colors.Black; plotCanvas.YAxis1.LineColor = Colors.Black; PackStart(plotCanvas.Canvas, true); Label la = new Label(infoText); PackStart(la); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); costPS = new Alt.GUI.NPlot.Temporary.Gwen.PlotSurface2DControl(this); costPS.AutoScaleAutoGeneratedAxes = false; costPS.AutoScaleTitle = false; costPS.DateTimeToolTip = false; costPS.Legend = null; costPS.LegendZOrder = -1; costPS.Location = new PointI(13, 13); costPS.Name = "costPS"; costPS.RightMenu = null; costPS.ShowCoordinates = false; costPS.Size = new SizeI(606, 285); costPS.SmoothingMode = SmoothingMode.None; costPS.SurfacePadding = 10; costPS.Title = ""; costPS.TitleFont = new Font("Arial", 14F, FontStyle.Regular, GraphicsUnit.Pixel); costPS.XAxis1 = null; costPS.XAxis2 = null; costPS.YAxis1 = null; costPS.YAxis2 = null; volumePS = new Alt.GUI.NPlot.Temporary.Gwen.PlotSurface2DControl(this); volumePS.AutoScaleAutoGeneratedAxes = false; volumePS.AutoScaleTitle = false; volumePS.DateTimeToolTip = false; volumePS.Legend = null; volumePS.LegendZOrder = -1; volumePS.Location = new PointI(13, 305); volumePS.Name = "volumePS"; volumePS.RightMenu = null; volumePS.ShowCoordinates = false; volumePS.Size = new SizeI(606, 109); volumePS.SmoothingMode = SmoothingMode.None; volumePS.SurfacePadding = 10; volumePS.Title = ""; volumePS.TitleFont = new Font("Arial", 14F, FontStyle.Regular, GraphicsUnit.Pixel); volumePS.XAxis1 = null; volumePS.XAxis2 = null; volumePS.YAxis1 = null; volumePS.YAxis2 = null; volumePS.Dock = Pos.Bottom; costPS.Dock = Pos.Fill; Padding = new Alt.GUI.Temporary.Gwen.Padding(20); costPS.Clear(); costPS.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 = Color.Red; cp.BullishColor = Color.Green; cp.Style = CandlePlot.Styles.Filled; costPS.SmoothingMode = 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.SurfacePadding = 5; costPS.AddInteraction(new Alt.GUI.NPlot.Temporary.Gwen.PlotSurface2DControl.Interactions.HorizontalDrag()); costPS.AddInteraction(new Alt.GUI.NPlot.Temporary.Gwen.PlotSurface2DControl.Interactions.VerticalDrag()); costPS.AddInteraction(new Alt.GUI.NPlot.Temporary.Gwen.PlotSurface2DControl.Interactions.AxisDrag(false)); costPS.InteractionOccured += new Alt.GUI.NPlot.Temporary.Gwen.PlotSurface2DControl.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.SurfacePadding = 5; volumePS.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60)); volumePS.AddInteraction(new Alt.GUI.NPlot.Temporary.Gwen.PlotSurface2DControl.Interactions.AxisDrag(false)); volumePS.AddInteraction(new Alt.GUI.NPlot.Temporary.Gwen.PlotSurface2DControl.Interactions.HorizontalDrag()); volumePS.InteractionOccured += new Alt.GUI.NPlot.Temporary.Gwen.PlotSurface2DControl.InteractionHandler(volumePS_InteractionOccured); volumePS.PreRefresh += new Alt.GUI.NPlot.Temporary.Gwen.PlotSurface2DControl.PreRefreshHandler(volumePS_PreRefresh); costPS.RightMenu = new ReducedContextMenu(costPS); SetPlotBackColor(); UpdateSize(); }
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 }
public FinancialDemo() { // // Required for Windows Form Designer support // InitializeComponent(); costPS.Clear(); costPS.DateTimeToolTip = true; // obtain stock information from xml file DataSet ds = new DataSet(); using (StringReader sr = new StringReader(Resources.asx_jbh)) ds.ReadXml(sr, 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(); }
public void CreatePlot() { costPS.Clear(); //costPS.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; 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.SurfacePadding = 5; costPS.AddInteraction(new PlotDrag(true, true)); costPS.AddInteraction(new AxisDrag()); costPS.InteractionOccurred += 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.SurfacePadding = 5; volumePS.AddAxesConstraint(new AxesConstraint.AxisPosition(PlotSurface2D.YAxisPosition.Left, 60)); volumePS.AddInteraction(new AxisDrag()); volumePS.AddInteraction(new PlotDrag(true, false)); volumePS.InteractionOccurred += volumePS_InteractionOccured; volumePS.PreRefresh += volumePS_PreRefresh; //this.costPS.RightMenu = new ReducedContextMenu(); }
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); }
public PlotDataset() { infoText = ""; infoText += "Stock Dataset Sample. Demonstrates - \n"; infoText += " * CandlePlot, FilledRegion, LinePlot and ArrowItem IDrawables \n"; infoText += " * DateTime axes \n"; infoText += " * Horizontal Drag Interaction - try dragging (and Ctrl-dragging) the plot surface \n"; infoText += " * Axis Drag Interaction - try dragging in the horizontal and vertical Axis areas"; plotSurface.Clear(); // [NOTIMP] plotSurface.DateTimeToolTip = true; // obtain stock information from xml file DataSet ds = new DataSet(); System.IO.Stream file = Assembly.GetExecutingAssembly().GetManifestResourceStream("SwfTest.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.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, false)); 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 FinancialDemo() : base("Multiple linked plot demo") { // // Gtk Window Setup // InitializeComponent(); costPS.Clear(); // obtain stock information from xml file DataSet ds = new DataSet(); System.IO.Stream file = Assembly.GetExecutingAssembly().GetManifestResourceStream("GtkTest.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.SurfacePadding = 5; costPS.AddInteraction(new NPlot.PlotDrag(true, true)); costPS.AddInteraction(new NPlot.AxisDrag()); costPS.InteractionOccurred += new NPlot.InteractivePlotSurface2D.InteractionHandler(costPS_InteractionOccurred); costPS.AddAxesConstraint(new AxesConstraint.Position(YAxisPosition.Left, 60)); costPS.Refresh(); 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.SurfacePadding = 5; volumePS.AddAxesConstraint(new AxesConstraint.Position(YAxisPosition.Left, 60)); volumePS.AddInteraction(new NPlot.AxisDrag()); volumePS.AddInteraction(new NPlot.PlotDrag(true, false)); volumePS.InteractionOccurred += new NPlot.InteractivePlotSurface2D.InteractionHandler(volumePS_InteractionOccurred); volumePS.PreRefresh += new NPlot.InteractivePlotSurface2D.PreRefreshHandler(volumePS_PreRefresh); volumePS.Refresh(); }
/// <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(); }