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 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 zoomOut(NPlot.Windows.PlotSurface2D plot) { double xLen = plot.XAxis1.WorldMax - plot.XAxis1.WorldMin; double newMinX = plot.XAxis1.WorldMin - xLen * 0.5; double newMaxX = plot.XAxis1.WorldMax + xLen * 0.5; if (newMinX < 0) { newMinX = 0; } if (newMaxX > this.maxValue[plot]) { newMaxX = this.maxValue[plot]; } plot.XAxis1.WorldMax = newMaxX; plot.XAxis1.WorldMin = newMinX; if (!timeScale.ContainsKey(plot)) { computeBarGraphTimeScales(); } this.SetBarGraphWidths(plot); plot.Refresh(); }
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(); }
public void SetBarGraphWidths(NPlot.Windows.PlotSurface2D canvas) { double numBars = (canvas.XAxis1.WorldLength) / (double)this.timeScale[canvas]; foreach (IDrawable drawable in canvas.Drawables) { if (drawable is BarPlot) { BarPlot bp = (BarPlot)drawable; bp.BarWidth = (float)Math.Floor(canvas.Width / (numBars)) - 4.0f; if (bp.BarWidth < 0) { bp.BarWidth = 1.0f; } } } canvas.Refresh(); }
/// <summary> /// Callback for QE example timer tick. /// </summary> /// <param name="sender">unused</param> /// <param name="e">unused</param> private void qeExampleTimer_Tick(object sender, System.EventArgs e) { Random r = new Random(); for (int i = 0; i < PlotQEExampleValues.Length; ++i) { PlotQEExampleValues[i] = 8.0f + 12.0f * (double)r.Next(10000) / 10000.0f; if (PlotQEExampleValues[i] > 18.0f) { PlotQEExampleTextValues[i] = "KCsTe"; } else { PlotQEExampleTextValues[i] = ""; } } plotSurface.Refresh(); }
public void SetData(string name, double pos, double value) { var line = GetLine(name); List <double> x = (List <double>)line.AbscissaData; List <double> y = (List <double>)line.OrdinateData; if (_base.XAxis1.WorldMax < pos) { _base.XAxis1.WorldMax = pos; } if (_base.YAxis1.WorldMax < value) { _base.YAxis1.WorldMax = value; } if (_base.YAxis1.WorldMin > value) { _base.YAxis1.WorldMin = value; } _base.XAxis1.WorldMin = 0; x.Add(pos); y.Add(value); _base.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(); } }
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); } }
/////////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()); } }
/// <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(); } }