public void AddToCanvas(VisFileContainer v) { Console.WriteLine("ADD CALLED"); int start, end; getRangeForDrawMode(v, this.drawMode, out start, out end); for (int i = start; i < end; i++) { // Console.WriteLine("Adding "+i); MyLinePlot linePlot = v.plotTable[y_key][i]; { linePlot.Name = v.filepath + i; canvas.Add(linePlot); } if (!containers.Contains(v)) { containers.Add(v); } } // p("NumDrawn="+this.itemsDrawn); if (true || isClear) { canvas.XAxis1.Label = x_label; canvas.YAxis1.Label = y_label; canvas.YAxis1.LabelOffsetAbsolute = true; canvas.YAxis1.LabelOffset = 40; canvas.XAxis1.HideTickText = false; isClear = false; } canvas.Refresh(); }
public void AddGraph(VisFileContainer v) { t.ColumnCount++; NPlot.Windows.PlotSurface2D plot = new NPlot.Windows.PlotSurface2D(); plot.Dock = DockStyle.Fill; foreach (BarPlot bp in v.barPlotTable[keyName]) { plot.Add(bp); } plot.Add(ComputeAveragePower(v)); plot.Legend = new Legend(); plot.Legend.HorizontalEdgePlacement = NPlot.Legend.Placement.Outside; plot.Legend.VerticalEdgePlacement = NPlot.Legend.Placement.Inside; plot.Legend.NumberItemsVertically = 4; plot.Legend.AttachTo(NPlot.PlotSurface2D.XAxisPosition.Bottom, NPlot.PlotSurface2D.YAxisPosition.Left); plot.Legend.YOffset = 40; plot.Title = v.deviceName + "\n" + v.configurationName; plot.Name = v.filepath; t.Controls.Add(plot, t.ColumnCount - 1, 0); t.ColumnStyles.Add(new ColumnStyle(SizeType.Percent)); RescaleBarGraphs(); }
public void RefreshPlots(NPlot.Windows.PlotSurface2D graphSurface) { graphSurface.Clear(); if (_plots.Count == 0) { graphSurface.Hide(); return; } foreach (var plot in _plots) { var lp = new LinePlot { Color = plot.PlotColour, AbscissaData = plot.XData, OrdinateData = plot.YData, Label = plot.PlotName }; graphSurface.Add(lp); } graphSurface.Title = "Pilot Trends"; var grid = new Grid { VerticalGridType = Grid.GridType.Fine, HorizontalGridType = Grid.GridType.Fine, MajorGridPen = new Pen(Color.LightGray, 0.5f) }; graphSurface.Add(grid); graphSurface.Refresh(); var leg = new Legend { HorizontalEdgePlacement = Legend.Placement.Inside, VerticalEdgePlacement = Legend.Placement.Outside, XOffset = 10, YOffset = 10 }; leg.AttachTo(PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Right); graphSurface.Legend = leg; graphSurface.LegendZOrder = 10; graphSurface.YAxis1.WorldMin = 0; graphSurface.XAxis1.Label = "Tour Number"; graphSurface.XAxis1.WorldMin -= 1; graphSurface.XAxis1.WorldMax += 1; graphSurface.Show(); graphSurface.Refresh(); }
public void InitPS(NPlot.Windows.PlotSurface2D PlotSurface2D) { PlotSurface2D.AutoScaleAutoGeneratedAxes = true; PlotSurface2D.AutoScaleTitle = false; PlotSurface2D.DateTimeToolTip = true; PlotSurface2D.Legend = null; PlotSurface2D.LegendZOrder = -1; //PS.Location = new System.Drawing.Point(0, 0); PlotSurface2D.Name = "costPS"; PlotSurface2D.RightMenu = null; PlotSurface2D.Padding = 1; //滑鼠tooltips 時間+價格 PlotSurface2D.ShowCoordinates = true; PlotSurface2D.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; PlotSurface2D.TabIndex = 2; PlotSurface2D.Title = "123"; PlotSurface2D.TitleFont = new System.Drawing.Font("Arial", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel); PlotSurface2D.Clear(); Grid mygrid = new Grid(); mygrid.HorizontalGridType = Grid.GridType.Fine; mygrid.VerticalGridType = Grid.GridType.Fine; PlotSurface2D.Add(mygrid); }
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 void InitLPP() { int[] times = { 500 }; lpp.DataSource = new int[] { 100 }; lpp.AbscissaData = times; lpp.Font = new Font("Arial", 25); lpp.Marker.Type = Marker.MarkerType.None; lpp.LabelTextPosition = LabelPointPlot.LabelPositions.Right; lpp.Marker.Size = 5; PS.Add(lpp); //NPlot.PointPlot pp = new PointPlot(); //pp.Marker.Pen = Pens.Red; //pp.Marker.Type = Marker.MarkerType.Triangle; //pp.Marker.FillBrush = Brushes.DarkRed; ////pp.Marker.Filled = true; //pp.Marker.Size = 50; //pp.DataSource = new int[] { 500 }; //pp.AbscissaData = new int[] { 200 }; //PS.Add(pp); }
private void RefreshPlot(plotType pType, bool legend, string title, string XLabel, int margin) { NPlot.Windows.PlotSurface2D surf = null; if (pType == plotType.Speed) { surf = SpeedPlot; } if (pType == plotType.Climb) { surf = ClimbPlot; } _numPlots = 0; foreach (int i in AircraftList.CheckedIndices) { DrawAircraft(pType, AircraftList.Items[i].ToString()); } if (_numPlots == 0) { return; } if (legend) { AttachLegend(surf); } surf.Title = title; surf.XAxis1.Label = XLabel; surf.YAxis1.Label = "feet"; surf.YAxis1.WorldMin = 0; surf.XAxis1.WorldMin -= margin; surf.XAxis1.WorldMax += margin; Grid grid = new Grid(); grid.VerticalGridType = Grid.GridType.Fine; grid.HorizontalGridType = Grid.GridType.Fine; grid.MajorGridPen = new Pen(Color.LightGray, 0.5f); surf.Add(grid); surf.Refresh(); }
LinePlot GetLine(string name) { LinePlot r; if (!_lines.ContainsKey(name)) { var tmp = new LinePlot(); tmp.Color = colorSample[_lines.Count]; tmp.Pen.Width = 2; tmp.AbscissaData = new List <double>(); tmp.OrdinateData = new List <double>(); _lines.Add(name, tmp); _base.Add(tmp); r = tmp; } else { r = _lines[name]; } return(r); }
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(); }
public void AddGraph(VisFileContainer v) { t.ColumnCount++; NPlot.Windows.PlotSurface2D plot = new NPlot.Windows.PlotSurface2D(); plot.Dock = DockStyle.Fill; foreach (BarPlot bp in v.barPlotTable[keyName]) { plot.Add(bp); } plot.Add(ComputeAveragePower(v)); plot.Legend = new Legend(); plot.Legend.HorizontalEdgePlacement = NPlot.Legend.Placement.Outside; plot.Legend.VerticalEdgePlacement = NPlot.Legend.Placement.Inside; plot.Legend.NumberItemsVertically = 4; plot.Legend.AttachTo(NPlot.PlotSurface2D.XAxisPosition.Bottom,NPlot.PlotSurface2D.YAxisPosition.Left); plot.Legend.YOffset = 40; plot.Title = v.deviceName+"\n"+v.configurationName; plot.Name = v.filepath; t.Controls.Add(plot,t.ColumnCount-1,0); t.ColumnStyles.Add(new ColumnStyle(SizeType.Percent)); RescaleBarGraphs(); }
/// <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(); }
private void PlotChart(QueryResultsEventArgs e, PlotSurface2D plot, List<KeyValuePair<int, Guid>> signals, bool cacheAxis) { if (cacheAxis) { double minX, maxX, minY, maxY; plot.Title = m_plotTitle; 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); foreach (KeyValuePair<int, Guid> freq in signals) { SignalDataBase data = e.Results[freq.Value]; List<double> y = new List<double>(data.Count); List<double> x = new List<double>(data.Count); for (int i = 0; i < data.Count; i++) { ulong time; double value; data.GetData(i, out time, out value); x.Add(time); y.Add(value * m_scalingFactor); } LinePlot lines = new LinePlot(y, x); lines.Pen = m_colorWheel.TryGetPen(freq.Key); 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.Title = m_plotTitle; AddInteractions(); foreach (KeyValuePair<int, Guid> freq in signals) { SignalDataBase data = e.Results[freq.Value]; List<double> y = new List<double>(data.Count); List<double> x = new List<double>(data.Count); for (int i = 0; i < data.Count; i++) { ulong time; double value; data.GetData(i, out time, out value); x.Add(time); y.Add(value * m_scalingFactor); } LinePlot lines = new LinePlot(y, x); lines.Pen = m_colorWheel.TryGetPen(freq.Key); plot.Add(lines); } if (plot.XAxis1 != null) { plot.XAxis1.WorldMax = e.EndTime.Ticks; plot.XAxis1.WorldMin = e.StartTime.Ticks; } plot.Refresh(); } }
public void OnLoadingFinished(Dictionary <ChannelInfo, DataTable> tables) { graph.Clear(); Grid myGrid = new Grid(); myGrid.VerticalGridType = Grid.GridType.Fine; myGrid.HorizontalGridType = Grid.GridType.Coarse; graph.Add(myGrid); Color[] availableColors = new Color[] { Color.Blue, Color.Red, Color.Violet, Color.Black, Color.Cyan, Color.Brown, Color.Yellow }; int trendNum = 0; foreach (ChannelInfo channelInfo in tables.Keys) { int valueColumnIndex = tables[channelInfo].Columns.IndexOf("Value"); int timeColumnIndex = tables[channelInfo].Columns.IndexOf("Time"); int valueCount = tables[channelInfo].Rows.Count; double[] values = new double[valueCount]; DateTime[] labels = new DateTime[valueCount]; for (int i = 0; i < valueCount; i++) { double.TryParse(tables[channelInfo].Rows[i].ItemArray[valueColumnIndex].ToString(), out values[i]); DateTime.TryParse(tables[channelInfo].Rows[i].ItemArray[timeColumnIndex].ToString(), out labels[i]); } LinePlot lp = new LinePlot(); lp.DataSource = values; lp.AbscissaData = labels; lp.Color = availableColors[trendNum % availableColors.Length]; lp.Label = channelInfo.ChannelName; graph.Add(lp); trendNum++; } Legend legend = new Legend(); legend.AttachTo(PlotSurface2D.XAxisPosition.Top, PlotSurface2D.YAxisPosition.Right); legend.HorizontalEdgePlacement = Legend.Placement.Inside; legend.VerticalEdgePlacement = Legend.Placement.Outside; legend.XOffset = 10; legend.YOffset = -10; graph.Legend = legend; graph.LegendZOrder = 1; graph.Visible = true; label1.Visible = false; Cursor = Cursors.Default; }
/////////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()); } }
private void PlotChart(QueryResultsEventArgs e, PlotSurface2D plot, List <KeyValuePair <int, Guid> > signals, bool cacheAxis) { if (cacheAxis) { double minX, maxX, minY, maxY; plot.Title = m_plotTitle; 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); } foreach (KeyValuePair <int, Guid> freq in signals) { SignalDataBase data = e.Results[freq.Value]; List <double> y = new List <double>(data.Count); List <double> x = new List <double>(data.Count); for (int i = 0; i < data.Count; i++) { ulong time; double value; data.GetData(i, out time, out value); x.Add(time); y.Add(value * m_scalingFactor); } LinePlot lines = new LinePlot(y, x); lines.Pen = m_colorWheel.TryGetPen(freq.Key); 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.Title = m_plotTitle; AddInteractions(); foreach (KeyValuePair <int, Guid> freq in signals) { SignalDataBase data = e.Results[freq.Value]; List <double> y = new List <double>(data.Count); List <double> x = new List <double>(data.Count); for (int i = 0; i < data.Count; i++) { ulong time; double value; data.GetData(i, out time, out value); x.Add(time); y.Add(value * m_scalingFactor); } LinePlot lines = new LinePlot(y, x); lines.Pen = m_colorWheel.TryGetPen(freq.Key); plot.Add(lines); } if (plot.XAxis1 != null) { plot.XAxis1.WorldMax = e.EndTime.Ticks; plot.XAxis1.WorldMin = e.StartTime.Ticks; } plot.Refresh(); } }
private void populateDataNPlot( List <string> arguments, List <string> series, List <List <object[]> > seriesValues, IList <object[]> argumentTotals, IList <object[]> seriesTotals, ReportSettings settings) { var chart = new PlotSurface2D { BackColor = SystemColors.Control, ForeColor = SystemColors.ControlText, PlotBackColor = SystemColors.Window, TitleColor = SystemColors.ControlText, SmoothingMode = SmoothingMode.HighQuality, Font = Font }; replaceChart(chart); if (arguments.Count == 0) { return; } var colorTransformation = new ColorSchemeTransformation(null) { IgnoreSaturation = true, AsBackground = true, }; var palette = _palette .Select(colorTransformation.TransformColor) .ToArray(); var summaryFields = settings.SummaryFields; chart.Legend = new Legend { BackgroundColor = SystemColors.Window, TextColor = SystemColors.WindowText, BorderColor = SystemColors.ActiveBorder }; chart.Legend.Font = chart.Legend.Font.ByDpi(); chart.Add(new Grid { VerticalGridType = Grid.GridType.Fine, HorizontalGridType = Grid.GridType.None, MinorGridPen = new Pen(SystemColors.GrayText) { DashPattern = new[] { 1f, 5f } }, MajorGridPen = new Pen(SystemColors.GrayText) }); var seriesSummaryLegend = new string[series.Count]; var argumentSummaryLegends = new List <string> [arguments.Count]; for (int i = 0; i < arguments.Count; i++) { argumentSummaryLegends[i] = new List <string>(); } var seriesList = new HistogramPlot[series.Count * summaryFields.Count]; float totalBarWidth = 0.75f; float barWidth = totalBarWidth / summaryFields.Count; double minY = double.MaxValue; double maxY = double.MinValue; var dataLabels = new List <TextItem>(); for (int k = 0; k < summaryFields.Count; k++) { float barOffset = (barWidth - totalBarWidth) * 0.5f + k * barWidth; string summaryFieldAlias = _fields.ByName[summaryFields[k]].Alias; string summaryFunctionAlias = Aggregates.Alias[settings.SummaryFunctions[k]]; var stackedYValues = new double[arguments.Count]; minY = Math.Min(0d, minY); maxY = Math.Max(0d, maxY); for (int j = 0; j < series.Count; j++) { int n = k * series.Count + j; Color color = palette[n % palette.Length]; var chartSeries = new HistogramPlot { Filled = true, RectangleBrush = new RectangleBrushes.Solid(color), BaseWidth = barWidth, BaseOffset = barOffset, Color = color, }; seriesList[n] = chartSeries; chart.Add(chartSeries); chartSeries.ShowInLegend = settings.ShowSeriesTotal; chartSeries.Label = series[j]; var yValues = Enumerable.Range(0, arguments.Count) .Select(i => Convert.ToDouble(seriesValues[j][i][k] ?? 0)) .ToList(); chartSeries.DataSource = yValues; for (int i = 0; i < arguments.Count; i++) { stackedYValues[i] += yValues[i]; } minY = Math.Min(minY, stackedYValues.Min()); maxY = Math.Max(maxY, stackedYValues.Max()); if (j > 0) { chartSeries.StackedTo(seriesList[n - 1]); } for (int i = 0; i < arguments.Count; i++) { double yValue = yValues[i]; if (yValue < 0.009) { continue; } string text; switch (settings.LabelDataElement) { case DataElement.SummaryField: text = $"{yValue:0.##}: {summaryFieldAlias}"; break; case DataElement.Series: text = $"{yValue:0.##}: {series[j]}"; break; case DataElement.Argument: text = $"{yValue:0.##}: {arguments[i]}"; break; case DataElement.SeriesAndArgument: text = $"{yValue:0.##}: {arguments[i]}, {series[j]}"; break; case DataElement.Values: text = $"{yValue:0.##}"; break; default: continue; } var labelY = stackedYValues[i] - yValue * 0.5; dataLabels.Add(new TextItem( new PointD(i + barOffset - 0.5f * barWidth + 0.05, labelY), text) { TextColor = SystemColors.ControlText, }); } } // if (settings.ShowSeriesTotal) // for (int j = 0; j < series.Count; j++) // { // string legend; // // bool seriesSet = settings.SeriesFields.Count > 1 || settings.SeriesFields[0] != string.Empty; // string seriesName; // if (seriesSet) // seriesName = series[j]; // else // seriesName = $"{summaryFunctionAlias} {summaryFieldAlias}"; // // if (settings.ExplainTotal && seriesSet) // legend = $"{seriesName}: {seriesTotals[j][k]}, {summaryFunctionAlias} {summaryFieldAlias}"; // else // legend = $"{seriesName}: {seriesTotals[j][k]}"; // // if (metadata.CanDisplayMultipleSeries) // seriesList[k * series.Count + j].LegendText = legend; // else // seriesSummaryLegend[j] = legend; // } // // if (settings.ShowArgumentTotal) // for (int i = 0; i < arguments.Count; i++) // { // string legend; // // if (settings.ExplainTotal) // legend = $"{arguments[i]}: {argumentTotals[i][k]}, {summaryFunctionAlias} {summaryFieldAlias}"; // else // legend = $"{arguments[i]}: {argumentTotals[i][k]}"; // // argumentSummaryLegends[i].Add(legend); // } } int largeTickStep = getLargeTickStep(maxY); chart.YAxis1 = new LinearAxis { WorldMin = minY, WorldMax = maxY + 0.5, LargeTickStep = largeTickStep, NumberOfSmallTicks = Math.Min(4, largeTickStep - 1), TickTextFont = Font, Color = SystemColors.WindowText, LabelColor = SystemColors.WindowText, TickTextColor = SystemColors.WindowText, }; var la = new LabelAxis { WorldMin = -0.5, WorldMax = arguments.Count - 0.5, TickTextFont = Font, Color = SystemColors.WindowText, LabelColor = SystemColors.WindowText, TickTextColor = SystemColors.WindowText, TickTextNextToAxis = false, TicksLabelAngle = 10f }; chart.XAxis1 = la; if (settings.ShowArgumentTotal) { var argumentSummaries = argumentSummaryLegends .Select(legends => string.Join("\n", legends)) .ToArray(); for (int i = 0; i < arguments.Count; i++) { la.AddLabel((arguments[i] + '\n' + argumentSummaries[i]).TrimEnd(), i); } } else { for (int i = 0; i < arguments.Count; i++) { la.AddLabel(arguments[i], i); } } foreach (TextItem label in dataLabels) { chart.Add(label); } }