public void UpdateGraph(XDate xValue, double roll, double pitch, double yaw) { this.imu_Roll_List.Add(xValue, roll); this.imu_Pitch_List.Add(xValue, pitch); this.imu_Yaw_List.Add(xValue, yaw); zedGraphControl1.Invalidate(); zedGraphControl1.AxisChange(); }
public void UpdateGraph(XDate xValue, double pid, double cmd, double feedback,double error,double rollRatePID) { //imuListYaw.Add(xValue, (double)imuYaw); pid_List.Add(xValue, pid); //roll_Rate_PID_List.Add(xValue, rollRatePID); //imuListPitch.Add(xValue, (double)imuPitch); cmd_List.Add(xValue, cmd); feedback_List.Add(xValue, feedback); Error_List.Add(xValue, error); //cmdlistRoll.Add(xValue, (double)cmdRoll); zedGraphControl1.Invalidate(); zedGraphControl1.AxisChange(); }
public CandleStickDemo() : base("Demonstration of the Candlestick Chart Type", "CandleStick Demo", DemoType.Bar) { GraphPane myPane = base.GraphPane; myPane.Title.Text = "Candlestick Chart Demo"; myPane.XAxis.Title.Text = "Trading Date"; myPane.YAxis.Title.Text = "Share Price, $US"; StockPointList spl = new StockPointList(); Random rand = new Random(); // First day is jan 1st XDate xDate = new XDate( 2006, 1, 1 ); double open = 50.0; for ( int i = 0; i < 50; i++ ) { double x = xDate.XLDate; double close = open + rand.NextDouble() * 10.0 - 5.0; double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0; double low = Math.Min( open, close ) - rand.NextDouble() * 5.0; StockPt pt = new StockPt( x, hi, low, open, close, 100000 ); spl.Add( pt ); open = close; // Advance one day xDate.AddDays( 1.0 ); // but skip the weekends if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 ) xDate.AddDays( 2.0 ); } CandleStickItem myCurve = myPane.AddCandleStick( "trades", spl, Color.Black ); myCurve.Stick.IsAutoSize = true; myCurve.Stick.Color = Color.Blue; // Use DateAsOrdinal to skip weekend gaps myPane.XAxis.Type = AxisType.DateAsOrdinal; myPane.XAxis.Scale.Min = new XDate( 2006, 1, 1 ); // pretty it up a little myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f ); myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f ); base.ZedGraphControl.AxisChange(); }
public FilledCurveDemo() : base("A Line Graph with the Area Under the Curves Filled", "Filled Curve Demo", DemoType.General, DemoType.Line) { GraphPane myPane = base.GraphPane; // Set the titles and axis labels myPane.Title.Text = "My Test Date Graph"; myPane.XAxis.Title.Text = "Date"; myPane.YAxis.Title.Text = "My Y Axis"; // Make up some data points from the Sine function PointPairList list = new PointPairList(); PointPairList list2 = new PointPairList(); for ( int i=0; i<36; i++ ) { double x = new XDate( 1995, i+1, 1 ); double y = Math.Sin( (double) i * Math.PI / 15.0 ); double y2 = 2 * y; list.Add( x, y ); list2.Add( x, y2 ); } // Generate a blue curve with circle symbols, and "My Curve 2" in the legend LineItem myCurve2 = myPane.AddCurve( "My Curve 2", list, Color.Blue, SymbolType.Circle ); // Fill the area under the curve with a white-red gradient at 45 degrees myCurve2.Line.Fill = new Fill( Color.White, Color.Red, 45F ); // Make the symbols opaque by filling them with white myCurve2.Symbol.Fill = new Fill( Color.White ); // Generate a red curve with diamond symbols, and "My Curve" in the legend LineItem myCurve = myPane.AddCurve( "My Curve", list2, Color.MediumVioletRed, SymbolType.Diamond ); // Fill the area under the curve with a white-green gradient myCurve.Line.Fill = new Fill( Color.White, Color.Green ); // Make the symbols opaque by filling them with white myCurve.Symbol.Fill = new Fill( Color.White ); // Set the XAxis to date type myPane.XAxis.Type = AxisType.Date; // Fill the axis background with a color gradient myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45F ); base.ZedGraphControl.AxisChange(); }
/// <summary> /// /// </summary> /// <param name="tbl"></param> /// <param name="cc"></param> /// <returns></returns> private IPointList GetPointList(DataTable tbl, GRDataCurveConfig cc) { PointPairList list = new PointPairList(); foreach (DataRow row in tbl.Rows) { DateTime dt = Convert.ToDateTime(row["DT"]); float value = Convert.ToSingle(row[cc.GRDataEnum.ToString()]); XDate xdt = new XDate(dt); list.Add(new PointPair(xdt, value)); } return list; }
/// <summary> /// Provides binding between <see cref="DataSource"/> and the specified pane. Extracts the /// data from <see cref="DataSource"/> and copies it into the appropriate /// <see cref="ZedGraph.IPointList"/> for each <see cref="ZedGraph.CurveItem"/> in the /// specified <see cref="ZedGraph.GraphPane"/>. /// </summary> /// <param name="g">The <see cref="Graphics"/> object to be used for rendering the data.</param> /// <param name="pane">The <see cref="ZedGraph.GraphPane"/> object which will receive the data.</param> protected void PopulateByDataSource( Graphics g, GraphPane pane ) { if ( this.CurveList.Count == 0 ) return; //If the Datasource column names are available we can bind them // correctly to their corresponding DataMember. if ( this.DataMember != null && this.DataMember != String.Empty && this.DataSource != null && this.DataSource is ITypedList && this.DataSource is IListSource ) { ITypedList tlist = this.DataSource as ITypedList; IListSource listSource = this.DataSource as IListSource; IList list = listSource.GetList(); PropertyDescriptorCollection pdc = tlist.GetItemProperties( null ); bool bListContainsList = listSource.ContainsListCollection; //Get the DataMember and Type of the base axis in the DataSource string baseDataMember = this.DataMember; PropertyDescriptor basePd = pdc.Find( baseDataMember, true ); if ( basePd == null ) throw new System.Exception( "Can't find DataMember '" + baseDataMember + "' in DataSource for the base axis." ); baseDataMember = basePd.Name; Type baseDataType = basePd.PropertyType; int indexBaseColumn = pdc.IndexOf( basePd ); //Foreach bar/curve // Get its DataMember and Type in the DataSource // Add the curve to the pane // Add all corresponding points(baseAxis,valueAxis,0) //Note: Z axis is not supported foreach ( ZedGraphWebCurveItem curveItem in this.CurveList ) { //Axis valueAxis = curveItem.ValueAxis; PropertyDescriptorCollection pdcValue = pdc; IList valueList = list; bool bValueListContainsList = bListContainsList; //If present, use DataSource of Curve instead of main DataSource if ( curveItem.DataSource != null && curveItem.DataSource is ITypedList && curveItem.DataSource is IListSource ) { ITypedList valueTlist = curveItem.DataSource as ITypedList; pdcValue = valueTlist.GetItemProperties( null ); IListSource valueListSource = curveItem.DataSource as IListSource; valueList = valueListSource.GetList(); bValueListContainsList = valueListSource.ContainsListCollection; } string valueDataMember = curveItem.DataMember; PropertyDescriptor pd = pdcValue.Find( valueDataMember, true ); if ( pd == null ) throw new System.Exception( "Can't find DataMember '" + valueDataMember + "' in DataSource for the " + curveItem.Label + " axis." ); valueDataMember = pd.Name; //Get the exact case-dependent name Type valueDataType = pd.PropertyType; int indexValueColumn = pdcValue.IndexOf( pd ); //Add points PointPairList points = new PointPairList(); PointPair pair = new PointPair(); object oColumnValue; try { int nRow = 0; foreach ( object row in list ) { // // Value axis binding (Y axis) // object valueRow = valueList[nRow]; //Get item value in 'row' if ( bValueListContainsList ) { if ( !( valueRow is IList ) ) throw new System.InvalidCastException( "The DataSource contains a list which declares its items as lists, but these don't support the IList interface." ); oColumnValue = ( valueRow as IList )[indexValueColumn]; } else { oColumnValue = pd.GetValue( valueRow ); } //Convert value to double (always double) double v = 0; switch ( oColumnValue.GetType().ToString() ) { case "System.DateTime": v = new XDate( Convert.ToDateTime( oColumnValue ) ).XLDate; break; default: try { v = Convert.ToDouble( oColumnValue ); } catch { throw new NotImplementedException( "Conversion from " + oColumnValue.GetType() + " to double not implemented." ); } break; } // // Base axis binding (X axis) // pair.Tag = oColumnValue; //Original typed value pair.Y = v; if ( this.XAxis.Type == AxisType.DateAsOrdinal || this.XAxis.Type == AxisType.Date ) { pair.X = new XDate( Convert.ToDateTime( basePd.GetValue( row ) ) ).XLDate; } else pair.X = Convert.ToDouble( basePd.GetValue( row ) ); points.Add( pair ); nRow++; } } catch ( System.ArgumentOutOfRangeException ) { //A local datasource was set on this curve but it has fewer rows than the axis datasource. //So we stop feeding this curve. } //Create curve in pane with its points curveItem.CreateInPane( pane, points ); } } else { //Add curves and values set in designer ZedGraphWebCurveItem curve; for ( int i = 0; i < CurveList.Count; i++ ) { curve = CurveList[i]; PointPairList points = new PointPairList(); PointPair pair = new PointPair(); for ( int j = 0; j < curve.Points.Count; j++ ) { curve.Points[j].CopyTo( pair ); points.Add( pair ); } curve.CreateInPane( pane, points ); } } //NOTE: ZedGraphWeb.DataMember = base axis //NOTE: ZedGraphCurveItem.DataMember = Y //NOTE: Z values are only supported via the callback (???) //TODO: cache the data-map table before processing rows (???) }
private void WidenDatesIfNeeded(XDate fDate, XDate lDate) { if (fDate.DateTime < _firstDate) _firstDate = fDate.DateTime; if (lDate.DateTime > _lastDate) _lastDate = lDate.DateTime; }
private void buttonZoomOut_Click(object sender, EventArgs e) { XDate startx = new XDate(_firstDate.Year, _firstDate.Month, _firstDate.Day, _firstDate.Hour, _firstDate.Minute, _firstDate.Second); XDate endx = new XDate(_lastDate.Year, _lastDate.Month, _lastDate.Day, _lastDate.Hour, _lastDate.Minute, _lastDate.Second); for (int i = 0; i < zedGraphControl1.MasterPane.PaneList.Count; i++) { zedGraphControl1.MasterPane[i].XAxis.Scale.Min = (double)startx; zedGraphControl1.MasterPane[i].XAxis.Scale.Max = (double)endx; } lbScrollTime.Text = "VIEWING ALL"; zedGraphControl1.AxisChange(); zedGraphControl1.Refresh(); if (_isAdaptingPointSize) SetPointSize(); }
public void UpdateGraph() { try { try { DateTime startTime = DateTime.Now; // Take a copy of the metrics file. if (File.Exists(m_metricsFileCopyName)) { File.Delete(m_metricsFileCopyName); } logger.Debug("Copying " + m_metricsFileName + " to " + m_metricsFileCopyName); File.Copy(m_metricsFileName, m_metricsFileCopyName); StreamReader metricsReader = new StreamReader(m_metricsFileCopyName); m_totalSIPPacketsList.Clear(); m_sipRequestsInList.Clear(); m_sipResponsesInList.Clear(); m_sipRequestsOutList.Clear(); m_sipResponsesOutList.Clear(); m_pendingTransactionsList.Clear(); m_discardsList.Clear(); m_unrecognisedList.Clear(); m_tooLargeList.Clear(); m_badSIPList.Clear(); m_stunList.Clear(); m_totalParseTimeList.Clear(); m_avgParseTimeList.Clear(); m_sipMethodsLists = new Dictionary<SIPMethodsEnum, RollingPointPairList>(); m_topTalkersLists.Clear(); m_topTalkersCount.Clear(); string metricsLine = metricsReader.ReadLine(); int sampleCount = 0; while (metricsLine != null) { #region Process metrics line. if (metricsLine.Trim().Length != 0 && Regex.Match(metricsLine, ",").Success) { string[] fields = metricsLine.Split(','); XDate sampleDate = new XDate(DateTime.Parse(fields[1])); int samplePeriod = Convert.ToInt32(fields[2]); // Sample period in seconds. if (samplePeriod == 0) { throw new ApplicationException("The sample period for a measurement was 0 in SIPTransportMetricsGraphAgent."); } if (metricsLine.StartsWith(m_trafficMetrics)) { try { m_totalSIPPacketsList.Add(sampleDate, Convert.ToDouble(fields[3]) / samplePeriod); m_sipRequestsInList.Add(sampleDate, Convert.ToDouble(fields[4]) / samplePeriod); m_sipResponsesInList.Add(sampleDate, Convert.ToDouble(fields[5]) / samplePeriod); m_sipRequestsOutList.Add(sampleDate, Convert.ToDouble(fields[6]) / samplePeriod); m_sipResponsesOutList.Add(sampleDate, Convert.ToDouble(fields[7]) / samplePeriod); m_pendingTransactionsList.Add(sampleDate, Convert.ToDouble(fields[8])); m_unrecognisedList.Add(sampleDate, Convert.ToDouble(fields[9]) / samplePeriod); m_badSIPList.Add(sampleDate, Convert.ToDouble(fields[10]) / samplePeriod); m_stunList.Add(sampleDate, Convert.ToDouble(fields[11]) / samplePeriod); m_discardsList.Add(sampleDate, Convert.ToDouble(fields[12]) / samplePeriod); m_tooLargeList.Add(sampleDate, Convert.ToDouble(fields[13]) / samplePeriod); m_totalParseTimeList.Add(sampleDate, Convert.ToDouble(fields[14]) / samplePeriod); m_avgParseTimeList.Add(sampleDate, Convert.ToDouble(fields[15])); sampleCount++; } catch (Exception sampleExcp) { logger.Warn("Could not process metrics sample: " + metricsLine + ". " + sampleExcp.Message); } } else if (metricsLine.StartsWith(m_methodMetrics)) { for (int index = 3; index < fields.Length; index++) { string[] methodSplit = fields[index].Split('='); SIPMethodsEnum method = SIPMethods.GetMethod(methodSplit[0]); int methodPackets = Convert.ToInt32(methodSplit[1]) / samplePeriod; if(!m_sipMethodsLists.ContainsKey(method)) { m_sipMethodsLists.Add(method, new RollingPointPairList(GRAPH_SAMPLES)); } m_sipMethodsLists[method].Add(sampleDate, methodPackets); } } else if (metricsLine.StartsWith(m_topTalkerMetrics)) { for (int index = 3; index < fields.Length; index++) { string[] talkersSplit = fields[index].Split('='); string topTalkerSocket = talkersSplit[0]; int topTalkerPackets = Convert.ToInt32(talkersSplit[1]) / samplePeriod; if (!m_topTalkersLists.ContainsKey(topTalkerSocket)) { m_topTalkersLists.Add(topTalkerSocket, new RollingPointPairList(GRAPH_SAMPLES)); m_topTalkersCount.Add(topTalkerSocket, 0); } //logger.Debug("Adding point for " + topTalkerSocket + " and " + topTalkerPackets + "."); m_topTalkersLists[topTalkerSocket].Add(sampleDate, topTalkerPackets); m_topTalkersCount[topTalkerSocket] = m_topTalkersCount[topTalkerSocket] + topTalkerPackets; } } } #endregion metricsLine = metricsReader.ReadLine(); } metricsReader.Close(); #region Create the traffic graphs. GraphPane totalSIPPacketsGraphPane = new GraphPane(new Rectangle(0, 0, GRAPH_WIDTH, GRAPH_HEIGHT), "Total SIP Packets per Second", "Time", "Packets/s"); GraphPane pendingSIPTransactionsGraphPane = new GraphPane(new Rectangle(0, 0, GRAPH_WIDTH, GRAPH_HEIGHT), "Pending SIP Transactions", "Time", "Total"); GraphPane breakdownGraphPane = new GraphPane(new Rectangle(0, 0, GRAPH_WIDTH, GRAPH_HEIGHT), "SIP Request and Responses per Second", "Time", "Packets/s"); GraphPane anomaliesGraphPane = new GraphPane(new Rectangle(0, 0, GRAPH_WIDTH, GRAPH_HEIGHT), "Anomalous Packets per Second", "Time", "Packets/s"); GraphPane totalParseTimesGraphPane = new GraphPane(new Rectangle(0, 0, GRAPH_WIDTH, GRAPH_HEIGHT), "SIP Packet Parse Time per Second", "Time", "Total Parse Tme (ms)/s"); GraphPane averageParseTimesGraphPane = new GraphPane(new Rectangle(0, 0, GRAPH_WIDTH, GRAPH_HEIGHT), "Average SIP Packet Parse Time", "Time", "Average Parse Tme (ms)"); totalSIPPacketsGraphPane.Legend.IsVisible = false; totalSIPPacketsGraphPane.XAxis.Type = AxisType.Date; totalSIPPacketsGraphPane.XAxis.Scale.Format = "HH:mm:ss"; pendingSIPTransactionsGraphPane.Legend.IsVisible = false; pendingSIPTransactionsGraphPane.XAxis.Type = AxisType.Date; pendingSIPTransactionsGraphPane.XAxis.Scale.Format = "HH:mm:ss"; breakdownGraphPane.Legend.Location.AlignH = AlignH.Right; breakdownGraphPane.XAxis.Type = AxisType.Date; breakdownGraphPane.XAxis.Scale.Format = "HH:mm:ss"; anomaliesGraphPane.XAxis.Type = AxisType.Date; anomaliesGraphPane.XAxis.Scale.Format = "HH:mm:ss"; totalParseTimesGraphPane.XAxis.Type = AxisType.Date; totalParseTimesGraphPane.Legend.IsVisible = false; totalParseTimesGraphPane.XAxis.Scale.Format = "HH:mm:ss"; averageParseTimesGraphPane.XAxis.Type = AxisType.Date; averageParseTimesGraphPane.Legend.IsVisible = false; averageParseTimesGraphPane.XAxis.Scale.Format = "HH:mm:ss"; LineItem totalSIPPacketsCurve = totalSIPPacketsGraphPane.AddCurve("Total SIP Packets", m_totalSIPPacketsList, Color.Black, SymbolType.None); LineItem pendingTransactionsCurve = pendingSIPTransactionsGraphPane.AddCurve("Pending SIP Transactions", m_pendingTransactionsList, Color.Black, SymbolType.None); LineItem sipRequestsInCurve = breakdownGraphPane.AddCurve("Requests In", m_sipRequestsInList, Color.Blue, SymbolType.None); LineItem sipResponsesInCurve = breakdownGraphPane.AddCurve("Responses In", m_sipResponsesInList, Color.DarkGreen, SymbolType.None); LineItem sipRequestsOutCurve = breakdownGraphPane.AddCurve("Requests Out", m_sipRequestsOutList, Color.BlueViolet, SymbolType.None); LineItem sipResponsesOutCurve = breakdownGraphPane.AddCurve("Responses Out", m_sipResponsesOutList, Color.DarkKhaki, SymbolType.None); LineItem discardsCurve = anomaliesGraphPane.AddCurve("Discards", m_discardsList, Color.Red, SymbolType.None); LineItem badSIPCurve = anomaliesGraphPane.AddCurve("Bad SIP", m_badSIPList, Color.Purple, SymbolType.None); LineItem unrecognisedCurve = anomaliesGraphPane.AddCurve("Unrecognised", m_unrecognisedList, Color.Green, SymbolType.None); LineItem tooLargeCurve = anomaliesGraphPane.AddCurve("Too Large", m_tooLargeList, Color.Coral, SymbolType.None); LineItem stunCurve = anomaliesGraphPane.AddCurve("STUN", m_stunList, Color.Blue, SymbolType.None); LineItem totalParseTimeCurve = totalParseTimesGraphPane.AddCurve("Total Parse Time", m_totalParseTimeList, Color.Black, SymbolType.None); LineItem averageParseTimeCurve = averageParseTimesGraphPane.AddCurve("Average Parse Time", m_avgParseTimeList, Color.Black, SymbolType.None); totalSIPPacketsGraphPane.AxisChange(m_g); pendingSIPTransactionsGraphPane.AxisChange(m_g); breakdownGraphPane.AxisChange(m_g); anomaliesGraphPane.AxisChange(m_g); totalParseTimesGraphPane.AxisChange(m_g); averageParseTimesGraphPane.AxisChange(m_g); Bitmap totalsGraphBitmap = totalSIPPacketsGraphPane.GetImage(); totalsGraphBitmap.Save(m_localGraphsDir + "siptotals.png", ImageFormat.Png); Bitmap pendingTransactionsGraphBitmap = pendingSIPTransactionsGraphPane.GetImage(); pendingTransactionsGraphBitmap.Save(m_localGraphsDir + "siptransactions.png", ImageFormat.Png); Bitmap breakdownGraphBitmap = breakdownGraphPane.GetImage(); breakdownGraphBitmap.Save(m_localGraphsDir + "sipmessagetypes.png", ImageFormat.Png); Bitmap anomaliesGraphBitmap = anomaliesGraphPane.GetImage(); anomaliesGraphBitmap.Save(m_localGraphsDir + "anomalies.png", ImageFormat.Png); Bitmap totalParseTimeGraphBitmap = totalParseTimesGraphPane.GetImage(); totalParseTimeGraphBitmap.Save(m_localGraphsDir + "siptotalparse.png", ImageFormat.Png); Bitmap averageParseTimeGraphBitmap = averageParseTimesGraphPane.GetImage(); averageParseTimeGraphBitmap.Save(m_localGraphsDir + "sipaverageparse.png", ImageFormat.Png); #endregion #region Create SIP methods graph. GraphPane methodsGraphPane = new GraphPane(new Rectangle(0, 0, GRAPH_WIDTH, GRAPH_HEIGHT), "SIP Packets for Method per Second", "Time", "SIP Packets/s"); methodsGraphPane.XAxis.Type = AxisType.Date; methodsGraphPane.XAxis.Scale.Format = "HH:mm:ss"; foreach (KeyValuePair<SIPMethodsEnum, RollingPointPairList> entry in m_sipMethodsLists) { Color methodColor = (m_methodColours.ContainsKey(entry.Key)) ? m_methodColours[entry.Key] : Color.Black; LineItem methodCurve = methodsGraphPane.AddCurve(entry.Key.ToString(), entry.Value, methodColor, SymbolType.None); } methodsGraphPane.AxisChange(m_g); Bitmap methodsGraphBitmap = methodsGraphPane.GetImage(); methodsGraphBitmap.Save(m_localGraphsDir + "sipmethods.png", ImageFormat.Png); #endregion #region Create top talkers graph. // Get the top 10 talkers. if (m_topTalkersCount.Count > 0) { string[] topTalkerSockets = new string[m_topTalkersCount.Count]; int[] topTalkerValues = new int[m_topTalkersCount.Count]; m_topTalkersCount.Keys.CopyTo(topTalkerSockets, 0); m_topTalkersCount.Values.CopyTo(topTalkerValues, 0); Array.Sort<int, string>(topTalkerValues, topTalkerSockets); GraphPane toptalkersGraphPane = new GraphPane(new Rectangle(0, 0, GRAPH_WIDTH, GRAPH_HEIGHT), "SIP Top Talkers", "Time", "SIP Packets/s"); toptalkersGraphPane.XAxis.Type = AxisType.Date; toptalkersGraphPane.XAxis.Scale.Format = "HH:mm:ss"; //foreach (KeyValuePair<string, RollingPointPairList> entry in m_topTalkersLists) for (int index = topTalkerSockets.Length - 1; (index >= topTalkerSockets.Length - NUMBER_TOPTALKERS_TOPPLOT && index >= 0); index--) { string socket = topTalkerSockets[index]; RollingPointPairList topTalkerPoints = m_topTalkersLists[socket]; Color topTalkerColor = m_topTalkerColours[topTalkerSockets.Length - 1 - index]; //logger.Debug("Adding curve for " + socket + " (count=" + topTalkerValues[index] + ")."); LineItem topTalkersCurve = toptalkersGraphPane.AddCurve(socket, topTalkerPoints, topTalkerColor, SymbolType.None); //break; } toptalkersGraphPane.AxisChange(m_g); Bitmap topTalkersGraphBitmap = toptalkersGraphPane.GetImage(); topTalkersGraphBitmap.Save(m_localGraphsDir + "siptoptalkers.png", ImageFormat.Png); } #endregion logger.Debug("Metrics graph for " + m_metricsFileCopyName + " completed in " + DateTime.Now.Subtract(startTime).TotalMilliseconds.ToString("0.##") + "ms, " + sampleCount + " samples."); #region Uplodad file to server. /*if (m_serverFilename != null && m_serverFilename.Trim().Length > 0) { Uri target = new Uri(m_serverFilename); FtpWebRequest request = (FtpWebRequest)WebRequest.Create(target); request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential("anonymous", "*****@*****.**"); FileStream localStream = File.OpenRead(m_totalsGraphFilename); Stream ftpStream = request.GetRequestStream(); byte[] buffer = new byte[localStream.Length]; localStream.Read(buffer, 0, buffer.Length); localStream.Close(); ftpStream.Write(buffer, 0, buffer.Length); ftpStream.Close(); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); response.Close(); //logger.Debug("Result of ftp upload to " + m_serverFilename + " is " + response.StatusDescription + "."); }*/ #endregion } catch (Exception graphExcp) { logger.Error("Exception Saving Graph. " + graphExcp.Message); } } catch (Exception excp) { logger.Debug("Exception UpdateGraph. " + excp.Message); } }
public void CreateGraph_junk5( ZedGraphControl zgc ) { GraphPane myPane = zgc.GraphPane; // Set the title and axis labels myPane.Title.Text = "Japanese Candlestick Chart Demo"; myPane.XAxis.Title.Text = "Trading Date"; myPane.YAxis.Title.Text = "Share Price, $US"; StockPointList spl = new StockPointList(); Random rand = new Random(); // First day is jan 1st XDate xDate = new XDate( 2006, 1, 1 ); double open = 50.0; for ( int i = 0; i < 1000; i++ ) { double x = xDate.XLDate; double close = open + rand.NextDouble() * 10.0 - 5.0; double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0; double low = Math.Min( open, close ) - rand.NextDouble() * 5.0; StockPt pt = new StockPt( x, hi, low, open, close, 100000 ); spl.Add( pt ); open = close; if ( xDate.DateTime.Hour < 23 ) xDate.AddHours( 1.0 ); else { // Advance one day xDate.AddHours( 1.0 ); // but skip the weekends if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 ) xDate.AddDays( 2.0 ); } } JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick( "trades", spl ); myCurve.Stick.IsAutoSize = true; myCurve.Stick.Color = Color.Blue; // Use DateAsOrdinal to skip weekend gaps myPane.XAxis.Type = AxisType.DateAsOrdinal; myPane.XAxis.Scale.Min = new XDate( 2006, 1, 1 ); myPane.XAxis.Scale.Format = "dd-MMM-yy hh:mm"; // pretty it up a little myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f ); myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f ); PointPairList ppl = new PointPairList(); for ( int i = 19; i < spl.Count; i++ ) { double avg = 0.0; for ( int j = 0; j < 20; j++ ) avg += spl.GetAt( i - j ).Close; ppl.Add( i + 1, avg / 20.0 ); } LineItem item = myPane.AddCurve( "MA-20", ppl, Color.Red ); item.IsOverrideOrdinal = true; item.Line.Width = 3; item.Symbol.Type = SymbolType.None; item.Line.IsSmooth = true; // Tell ZedGraph to calculate the axis ranges zgc.AxisChange(); zgc.Invalidate(); }
// Basic curve test - Line Graph with DateAsOrdinal private void CreateGraph_DateAsOrdinal( ZedGraphControl z1 ) { GraphPane myPane = z1.GraphPane; PointPairList list = new PointPairList(); for ( int i = 0; i < 100; i++ ) { double x = new XDate( 2007, 6, 3 + i ); double y = Math.Sin( i / 8.0 ) * 1 + 1; list.Add( x, y ); } LineItem myCurve = myPane.AddCurve( "curve", list, Color.Blue, SymbolType.Diamond ); myPane.XAxis.Type = AxisType.DateAsOrdinal; z1.AxisChange(); //myPane.YAxis.Scale.Format = "0.0'%'"; }
public void CreateGraph_SortedOverlayBars2( ZedGraphControl zgc ) { GraphPane myPane = zgc.GraphPane; const int count = 52; PointPairList ppl1 = new PointPairList(); PointPairList ppl2 = new PointPairList(); PointPairList ppl3 = new PointPairList(); double val1 = 50.0; double val2 = 50.0; double val3 = 50.0; Random rand = new Random(); XDate xDate = new XDate( 2005, 1, 1 ); for ( int i = 0; i < count; i++ ) { //double x = i + 1; val1 += rand.NextDouble() * 10.0 - 5.0; val2 += rand.NextDouble() * 10.0 - 5.0; val3 += rand.NextDouble() * 10.0 - 5.0; if ( i == 30 ) xDate.AddDays( 7 ); //double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0; //double low = Math.Min( open, close ) - rand.NextDouble() * 5.0; ppl1.Add( xDate, val1 ); ppl2.Add( xDate, val2 ); ppl3.Add( xDate, val3 ); xDate.AddDays( 7 ); } // Generate a red bar with "Curve 1" in the legend CurveItem myCurve = myPane.AddBar( "Curve 1", ppl1, Color.Red ); // Generate a blue bar with "Curve 2" in the legend myCurve = myPane.AddBar( "Curve 2", ppl2, Color.Blue ); // Generate a green bar with "Curve 3" in the legend myCurve = myPane.AddBar( "Curve 3", ppl3, Color.Green ); //myPane.XAxis.Type = AxisType.DateAsOrdinal; myPane.XAxis.Type = AxisType.Date; // Make the bars a sorted overlay type so that they are drawn on top of eachother // (without summing), and each stack is sorted so the shorter bars are in front // of the taller bars myPane.BarSettings.Type = BarType.SortedOverlay; // Fill the axis background with a color gradient myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0F ); // Calculate the Axis Scale Ranges zgc.AxisChange(); }
// Make a masterpane with 3 charts // Top = OHLC Bar Chart // Mid = Volume Chart // Bot = Price Change public void CreateGraph_OHLCBarMaster( ZedGraphControl zgc ) { // ================================================ // First, set up some lists with random data... // ================================================ StockPointList spl = new StockPointList(); PointPairList volList = new PointPairList(); PointPairList changeList = new PointPairList(); Random rand = new Random(); // First day is jan 1st XDate xDate = new XDate( 2006, 1, 1 ); double open = 50.0; double prevClose = 50.0; const int numDays = 365; // Loop to make 365 days of data for ( int i = 0; i < numDays; i++ ) { double x = xDate.XLDate; //double close = open + rand.NextDouble() * 10.0 - 5.0; double close = open * ( 0.95 + rand.NextDouble() * 0.1 ); //double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0; //double low = Math.Min( open, close ) - rand.NextDouble() * 5.0; double hi = Math.Max( open, close ) * ( 1.0 + rand.NextDouble() * 0.05 ); double low = Math.Min( open, close ) * ( 0.95 + rand.NextDouble() * 0.05 ); double vol = 25.0 + rand.NextDouble() * 100.0; double change = close - prevClose; // Create a StockPt instead of a PointPair so we can carry 6 properties StockPt pt = new StockPt( x, hi, low, open, close, vol ); //if price is increasing color=black, else color=red pt.ColorValue = close > prevClose ? 2 : 1; spl.Add( pt ); volList.Add( x, vol ); changeList.Add( x, change ); prevClose = close; open = close; // Advance one day xDate.AddDays( 1.0 ); // but skip the weekends if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 ) xDate.AddDays( 2.0 ); } // ================================================ // Create 3 GraphPanes to display the data // ================================================ // get a reference to the masterpane MasterPane master = zgc.MasterPane; // The first chart is already in the MasterPane, so add the other two charts master.Add( new GraphPane() ); master.Add( new GraphPane() ); // ================================================ // The first pane is an OHLCBarItem // ================================================ // Get a reference to the pane GraphPane pane = master[0]; // Set the title and axis labels pane.Title.Text = "Open-High-Low-Close History"; pane.XAxis.Title.Text = "Date"; pane.YAxis.Title.Text = "Price"; // Setup the gradient fill... // Use Red for negative days and black for positive days Color[] colors = { Color.Red, Color.Black }; Fill myFill = new Fill( colors ); myFill.Type = FillType.GradientByColorValue; myFill.SecondaryValueGradientColor = Color.Empty; myFill.RangeMin = 1; myFill.RangeMax = 2; //Create the OHLC and assign it a Fill OHLCBarItem ohlcCurve = pane.AddOHLCBar( "Price", spl, Color.Empty ); ohlcCurve.Bar.GradientFill = myFill; ohlcCurve.Bar.IsAutoSize = true; // Create a JapaneseCandleStick //JapaneseCandleStickItem jcsCurve = pane.AddJapaneseCandleStick( "Price", spl ); //jcsCurve.Stick.IsAutoSize = false; // ================================================ // The second pane is a regular BarItem to show daily volume // ================================================ // Get a reference to the pane pane = master[1]; // Set the title and axis labels pane.Title.Text = "Daily Volume"; pane.XAxis.Title.Text = "Date"; pane.YAxis.Title.Text = "Volume, thousands"; BarItem volBar = pane.AddBar( "Volume", volList, Color.Blue ); // ================================================ // The third pane is a LineItem to show daily price change // ================================================ // Get a reference to the pane pane = master[2]; // Set the title and axis labels pane.Title.Text = "Price Change"; pane.XAxis.Title.Text = "Date"; pane.YAxis.Title.Text = "Price Change, $"; LineItem changeCurve = pane.AddCurve( "Price Change", changeList, Color.Green, SymbolType.None ); // ================================================ // These settings are common to all three panes // ================================================ foreach ( GraphPane paneT in master.PaneList ) { // Use DateAsOrdinal to skip weekend gaps paneT.XAxis.Type = AxisType.DateAsOrdinal; // Use only visible data to define Y scale range paneT.IsBoundedRanges = true; // Define a minimum buffer space to the axes can be aligned paneT.YAxis.MinSpace = 80; paneT.Y2Axis.MinSpace = 50; // pretty it up a little paneT.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f ); paneT.Title.FontSpec.Size = 20.0f; paneT.XAxis.Title.FontSpec.Size = 18.0f; paneT.XAxis.Scale.FontSpec.Size = 16.0f; paneT.YAxis.Title.FontSpec.Size = 18.0f; paneT.YAxis.Scale.FontSpec.Size = 16.0f; paneT.Legend.IsVisible = false; paneT.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f ); // Set the initial scroll position and range // Note that the min and max for DateAsOrdinal scale will be ordinal values, not dates paneT.XAxis.Scale.Min = 1.0; // default range is 30 days paneT.XAxis.Scale.Max = 30.0; } // ================================================ // Set up the MasterPane Layout // ================================================ // Make sure that fonts and dimensions are the same for all three charts master.IsCommonScaleFactor = true; // Show the masterpane title master.Title.IsVisible = true; master.Title.Text = "Wacky Widget Company Stock Performance"; master.Fill = new Fill( Color.White, Color.SlateBlue, 45.0f ); // Leave a margin around the masterpane, but only a small gap between panes master.Margin.All = 10; master.InnerPaneGap = 5; using ( Graphics g = this.CreateGraphics() ) { master.SetLayout( g, PaneLayout.SingleColumn ); // Synchronize the Axes zgc.IsAutoScrollRange = true; zgc.IsShowHScrollBar = true; zgc.IsSynchronizeXAxes = true; // Scale range will extend about 1 day before and after the actual data range zgc.ScrollGrace = 1.0 / numDays; } // Tell ZedGraph to calculate the axis ranges zgc.AxisChange(); // master[0].XAxis.Scale.Min = new XDate( 2006, 1, 1 ).XLDate; // master[0].XAxis.Scale.Max = master[0].XAxis.Scale.Min + 30.0; // master[1].XAxis.Scale.Min = new XDate( 2006, 1, 1 ).XLDate; // master[1].XAxis.Scale.Max = master[1].XAxis.Scale.Min + 30.0; // master[2].XAxis.Scale.Min = new XDate( 2006, 1, 1 ).XLDate; // master[2].XAxis.Scale.Max = master[2].XAxis.Scale.Min + 30.0; //zgc.ScrollDoneEvent += new ZedGraphControl.ScrollDoneHandler( zgc_ScrollDoneEvent ); zgc.ScrollProgressEvent += new ZedGraphControl.ScrollProgressHandler( zgc_ScrollProgressEvent ); }
public void CreateGraph_OHLCBarGradient( ZedGraphControl zgc ) { GraphPane myPane = zgc.GraphPane; // Set the title and axis labels myPane.Title.Text = "OHLC Chart Demo"; myPane.XAxis.Title.Text = "Date"; myPane.YAxis.Title.Text = "Price"; //Load a StockPointList with random data......................... StockPointList spl = new StockPointList(); Random rand = new Random(); // First day is jan 1st XDate xDate = new XDate( 2006, 1, 1 ); double open = 50.0; double prevClose = 0; // Loop to make 50 days of data for ( int i = 0; i < 50; i++ ) { double x = xDate.XLDate; double close = open + rand.NextDouble() * 10.0 - 5.0; double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0; double low = Math.Min( open, close ) - rand.NextDouble() * 5.0; // Create a StockPt instead of a PointPair so we can carry 6 properties StockPt pt = new StockPt( x, hi, low, open, close, 100000 ); //if price is increasing color=black, else color=red pt.ColorValue = close > prevClose ? 2 : 1; spl.Add( pt ); prevClose = close; open = close; // Advance one day xDate.AddDays( 1.0 ); // but skip the weekends if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 ) xDate.AddDays( 2.0 ); } // Setup the gradient fill... // Use Red for negative days and black for positive days Color[] colors = { Color.Red, Color.Black }; Fill myFill = new Fill( colors ); myFill.Type = FillType.GradientByColorValue; myFill.SecondaryValueGradientColor = Color.Empty; myFill.RangeMin = 1; myFill.RangeMax = 2; //Create the OHLC and assign it a Fill OHLCBarItem myCurve = myPane.AddOHLCBar( "Price", spl, Color.Empty ); myCurve.Bar.GradientFill = myFill; myCurve.Bar.IsAutoSize = true; // Use DateAsOrdinal to skip weekend gaps myPane.XAxis.Type = AxisType.DateAsOrdinal; //myPane.XAxis.Scale.Min = new XDate( 2006, 1, 1 ); // pretty it up a little myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f ); myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f ); myPane.Title.FontSpec.Size = 20.0f; myPane.XAxis.Title.FontSpec.Size = 18.0f; myPane.XAxis.Scale.FontSpec.Size = 16.0f; myPane.YAxis.Title.FontSpec.Size = 18.0f; myPane.YAxis.Scale.FontSpec.Size = 16.0f; myPane.Legend.IsVisible = false; // BoxObj box = new BoxObj( 4.5, 0.0, 1.0, 1.0, Color.Transparent, // Color.FromArgb( 100, Color.LightBlue ) ); // box.Location.CoordinateFrame = CoordType.XScaleYChartFraction; // myPane.GraphObjList.Add( box ); // Tell ZedGraph to calculate the axis ranges zgc.AxisChange(); zgc.Invalidate(); }
private MemoryStream CreatePlayerCountImageOneMonth(GameServer server, out string fileName) { LordControl.PlayerCountStatisticInfo[] _infoArray = null; DateTime _endTime = DateTime.Now; DateTime _startTime = _endTime.AddMonths(-1); _infoArray = server.GetPlugInData(0, LordControl.PlugInGuid, LordControl.DataKeyPlayerCountStatistic, _startTime, _endTime) as LordControl.PlayerCountStatisticInfo[]; if (_infoArray.Length != 0) { ArrayList playerCountArrayList = new ArrayList(); LordControl.PlayerCountStatisticInfo tempInfo = new LordControl.PlayerCountStatisticInfo(); tempInfo.Time = _infoArray[0].Time; int countInOneDay = 0; for (int i = 0; i < _infoArray.Length; i++) { LordControl.PlayerCountStatisticInfo info = _infoArray[i]; if (tempInfo.Time.Date == info.Time.Date) { if (info.MaxCount > tempInfo.MaxCount) tempInfo.MaxCount = info.MaxCount; if (info.MinCount < tempInfo.MinCount) tempInfo.MinCount = info.MinCount; tempInfo.AverageCount += info.AverageCount; countInOneDay++; if (i == _infoArray.Length - 1) { tempInfo.AverageCount /= countInOneDay; playerCountArrayList.Add(tempInfo); } } else { tempInfo.AverageCount /= countInOneDay; playerCountArrayList.Add(tempInfo); tempInfo = new LordControl.PlayerCountStatisticInfo(); tempInfo.Time = info.Time; tempInfo.AverageCount = info.AverageCount; tempInfo.MaxCount = info.MaxCount; tempInfo.MinCount = info.MinCount; countInOneDay = 1; if (i == _infoArray.Length - 1) { playerCountArrayList.Add(tempInfo); } } } double[] maxCountArray = new double[playerCountArrayList.Count]; double[] minCountArray = new double[playerCountArrayList.Count]; double[] averageCountArray = new double[playerCountArrayList.Count]; double[] timeArray = new double[playerCountArrayList.Count]; for (int i = 0; i < playerCountArrayList.Count; i++) { LordControl.PlayerCountStatisticInfo info = playerCountArrayList[i] as LordControl.PlayerCountStatisticInfo; maxCountArray[i] = info.MaxCount; minCountArray[i] = info.MinCount; averageCountArray[i] = info.AverageCount; timeArray[i] = new XDate(info.Time); } GraphPane graphPane = new GraphPane(new Rectangle(0, 0, 840, 450), String.Empty, String.Empty, String.Empty); graphPane.Fill = new Fill(Color.FromArgb(212, 208, 200)); graphPane.Legend.Fill.IsVisible = false; graphPane.Legend.Border.IsVisible = false; graphPane.Legend.FontSpec.Fill.IsVisible = false; graphPane.XAxis.Title.Text = "时间"; graphPane.XAxis.MajorGrid.Color = Color.DarkGreen; graphPane.XAxis.Type = AxisType.Date; graphPane.XAxis.Scale.FontSpec.Size = 11; graphPane.YAxis.Title.Text = "玩家数量"; //graphPane.YAxis.MajorGrid.IsVisible = true; //graphPane.YAxis.MajorGrid.DashOff = 0; //graphPane.YAxis.MajorGrid.Color = Color.Gray; //graphPane.YAxis.MinorGrid.IsVisible = true; //graphPane.YAxis.MinorGrid.Color = Color.LightGray; //graphPane.YAxis.MinorGrid.DashOff = 0; graphPane.YAxis.Scale.Min = 0; graphPane.Title.Text = string.Format("{0} [ {1} {2} ]", "玩家数量", _startTime, _endTime); graphPane.AddCurve("最大", timeArray, maxCountArray, Color.Red, SymbolType.Triangle); graphPane.AddCurve("最小", timeArray, minCountArray, Color.Green, SymbolType.TriangleDown); graphPane.AddCurve("平均", timeArray, averageCountArray, Color.Orange, SymbolType.Diamond); graphPane.AxisChange(); fileName = server.Group.Name + "-" + DateTime.Now.Date.ToString("yyyy-MM-dd") + "-(Month)" + ".jpg"; MemoryStream imageMemoryStream = new MemoryStream(); graphPane.GetImage().Save(imageMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); imageMemoryStream.Position = 0; return imageMemoryStream; } else { fileName = String.Empty; return null; } }
private void CreateGraph_StickToCurve( ZedGraphControl z1 ) { PointPairList listCurve = new PointPairList(); PointPairList listPts = new PointPairList(); Random rand = new Random(); double val = 155.0; XDate date = new XDate( 2005, 7, 1 ); for ( int iDay = 0; iDay < 60; iDay++ ) { double dv = rand.NextDouble() * 3 - 1.5; listCurve.Add( date, val ); listPts.Add( date, val + dv, val ); val += rand.NextDouble() * 0.4 - 0.3; date.AddDays( 1 ); } GraphPane myPane = z1.GraphPane; myPane.XAxis.Type = AxisType.Date; myPane.AddCurve( "val", listCurve, Color.Red, SymbolType.None ); LineItem scatter = myPane.AddCurve( "pts", listPts, Color.Blue, SymbolType.Diamond ); scatter.Line.IsVisible = false; scatter.Symbol.Fill = new Fill( Color.White ); scatter.Symbol.Size = 5; ErrorBarItem myBar = myPane.AddErrorBar( "bars", listPts, Color.Green ); myBar.Bar.Symbol.IsVisible = false; z1.AxisChange(); }
public void CreateGraph_Junk2( ZedGraphControl z1 ) { DateTime dateTime = new DateTime( 2006, 6, 16 ); int hours = 1; double d1 = new XDate( dateTime - new TimeSpan( hours, 59, 59 ) ); double d2 = new XDate( dateTime + new TimeSpan( 0, 0, 59 ) ); //XDate x1 = d1 ); //XDate x2 = new XDate( d2 ); GraphPane pane = z1.GraphPane; pane.Title.Text = "Log Book"; pane.LineType = LineType.Stack; pane.XAxis.Scale.Max = 24; pane.YAxis.Scale.Max = 4.5; string[] labels = { "Off Duty", "Sleeper Berth", "On Duty Driving", "On Duty Not Driving" }; double[] x = { }; double[] y = { }; LineItem line = pane.AddCurve( "Driver1", x, y, Color.Red ); line.Line.StepType = StepType.ForwardStep; line.Symbol.IsVisible = false; line.AddPoint( 0, 0 ); line.AddPoint( 2, 2 ); line.AddPoint( 9, 4 ); line.AddPoint( 13, 2 ); line.AddPoint( 24, 1 ); pane.YAxis.MajorTic.IsBetweenLabels = true; pane.YAxis.Scale.TextLabels = labels; pane.YAxis.Type = AxisType.Text; pane.Chart.Fill = new Fill( Color.White, Color.LightSkyBlue, 45.0F ); z1.AxisChange(); }
// Basic curve test - Date Axis private void CreateGraph_DateAxis( ZedGraphControl z1 ) { GraphPane myPane = z1.GraphPane; PointPairList list = new PointPairList(); PointPairList list2 = new PointPairList(); for ( int i = 0; i < 50; i++ ) { double x = new XDate( 2005, 12 + i, 15 ); double y = Math.Sin( i / 8.0 ) * 1000 + 1001; list.Add( x, y, 1500 ); list2.Add( x, y * 1.2, 1500 ); } LineItem line = myPane.AddCurve( "Line", list, Color.Blue, SymbolType.Diamond ); //myPane.XAxis.Scale.Format = "MMM\nyyyy"; myPane.XAxis.Type = AxisType.Date; //myPane.XAxis.Scale.MajorStep = 1; //myPane.XAxis.Scale.MajorUnit = DateUnit.Year; myPane.XAxis.Scale.MinorStep = 1; myPane.XAxis.Scale.MinorUnit = DateUnit.Month; /* BarItem myBar = myPane.AddBar( "Bar", list, Color.Blue ); BarItem myBar2 = myPane.AddBar( "Bar2", list2, Color.Green ); //LineItem myCurve = myPane.AddCurve( "curve", list, Color.Blue, SymbolType.Diamond ); myPane.BarSettings.Type = BarType.ClusterHiLow; myPane.BarSettings.ClusterScaleWidth = 20.0; */ z1.IsAutoScrollRange = true; z1.IsShowHScrollBar = true; z1.IsShowVScrollBar = true; XDate now = new XDate( DateTime.Now ); ArrowObj arrow = new ArrowObj( Color.Black, 2.0f, (float) now.XLDate, 0.0f, (float) now.XLDate, 1.0f ); arrow.IsArrowHead = false; arrow.Location.CoordinateFrame = CoordType.XScaleYChartFraction; arrow.IsClippedToChartRect = true; myPane.GraphObjList.Add( arrow ); // Make the first year line double xDate = new XDate( 2006, 1, 1 ).XLDate; LineObj myLine = new LineObj(); myLine.Location.X1 = xDate; myLine.Location.Y1 = 0.0; myLine.Location.Width = 0.0; myLine.Location.Height = 1.0; myLine.IsClippedToChartRect = true; myLine.Location.CoordinateFrame = CoordType.XScaleYChartFraction; myLine.Line.Width = 2.0f; myLine.Line.Color = Color.Red; myPane.GraphObjList.Add( myLine ); // Repeat for each Grid by cloning xDate = new XDate( 2007, 1, 1 ).XLDate; ; myLine = new LineObj( myLine ); myLine.Location.X1 = xDate; myPane.GraphObjList.Add( myLine ); }
public void CreateGraph_junk9( ZedGraphControl z1 ) { GraphPane myPane = z1.GraphPane; myPane.BarSettings.Base = BarBase.Y; PointPairList ppl = new PointPairList(); PointPairCV pp1 = new PointPairCV( 20, 25, 10 ); PointPairCV pp2 = new PointPairCV( 30, 30, 20 ); PointPairCV pp3 = new PointPairCV( 40, 35, 15 ); PointPairCV pp4 = new PointPairCV( 50, 40, 30 ); PointPairCV pp5 = new PointPairCV( 60, 45, 10 ); pp1.ColorValue = 1; pp2.ColorValue = 2; pp3.ColorValue = 3; pp4.ColorValue = 4; pp5.ColorValue = 5; ppl.Add( pp1 ); ppl.Add( pp2 ); ppl.Add( pp3 ); ppl.Add( pp4 ); ppl.Add( pp5 ); XDate myXDate = new XDate( 2007, 5, 6 ); double poop = myXDate.XLDate; // double cv = ( ppl[3] as PointPairCV ).ColorValue; Color[] colors = { Color.Red, Color.Green, Color.Blue, Color.Cyan, Color.LightGreen }; Fill myFill = new Fill( colors ); myFill.Type = FillType.GradientByColorValue; myFill.SecondaryValueGradientColor = Color.White; myFill.RangeMin = 1; myFill.RangeMax = 5; HiLowBarItem myCurve = myPane.AddHiLowBar( "Curve 1", ppl, Color.Empty ); myCurve.Bar.Fill = myFill; // myCurve.Bar.Size = 20; }
// Simple plot with interpolated difference curve private void CreateGraph_DifferencePlot( ZedGraphControl z1 ) { GraphPane myPane = z1.GraphPane; // Generate the first data set PointPairList list1 = new PointPairList(); for ( int i = 0; i < 13; i++ ) { double x = i + 11.0; double y = 150.0 * ( 1.0 + Math.Sin( i * 0.3 ) ); list1.Add( x, y ); } // Generate a second data set that is unrelated to the first PointPairList list2 = new PointPairList(); for ( int i = 0; i < 15; i++ ) { double x = i * 1.2 + 10.0; double y = 250.0 * ( 1.0 + Math.Sin( x * 0.5 ) ); list2.Add( x, y ); } // Make sure the data are sorted and monotonically increasing list1.Sort(); list2.Sort(); // Get the lower and upper limit of the data // This code can throw an exception if either list is empty double xMin = Math.Min( list1[0].X, list2[0].X ); double xMax = Math.Max( list1[list1.Count - 1].X, list2[list2.Count - 1].X ); // Create a new list that will hold the difference points PointPairList diffList = new PointPairList(); // Select the number of points for the new difference curve // This is completely arbitrary, but more points will make it smoother in the // case of SplineInterpolation const int count = 50; // Loop for each data point to be created in the new PointPairList for ( int i=0; i<count; i++ ) { // Calculated X values are evenly spaced double x = xMin + (double) i * ( xMax - xMin ) / count; // Use spline interpolation to create the Y values for the new curve // Note that this allows extrapolation beyond the actual data available // A tension value of 0.5 is used, but anywhere between 0 and 1 is reasonable //double y = list1.InterpolateX( x ); double y1 = list1.InterpolateX( x ); double y2 = list2.SplineInterpolateX( x, 0.5 ); // Add the new Point to the list taking the difference between the Y values // If either value is Missing, it means that a point was extrapolated beyond // the available data, which is not allowed for SplineInterpolateX() // This won't happen with InterpolateX, since it allows extrapolation if ( y1 == PointPair.Missing || y2 == PointPair.Missing ) diffList.Add( x, PointPair.Missing, PointPair.Missing ); else diffList.Add( x, y1 - y2, (y1-y2) > 0 ? 1 : 0 ); } // Create the three curves -- two datasets, plus a difference curve LineItem diffCurve = myPane.AddCurve( "diff", diffList, Color.Red, SymbolType.None ); LineItem myCurve1 = myPane.AddCurve( "curve", list1, Color.Blue, SymbolType.Diamond ); LineItem myCurve2 = myPane.AddCurve( "curve 2", list2, Color.Green, SymbolType.Circle ); Color[] colors = { Color.Red, Color.Green }; diffCurve.Line.Fill = new Fill( colors, 90 ); diffCurve.Line.Fill.RangeMin = 0; diffCurve.Line.Fill.RangeMax = 1; diffCurve.Line.Fill.Type = FillType.GradientByZ; //diffCurve.Line.GradientFill = new Fill( colors, 90 ); //diffCurve.Line.GradientFill.RangeMin = -100; //diffCurve.Line.GradientFill.RangeMax = 200; //diffCurve.Line.IsOptimizedDraw = true; // Add some "pretty" stuff (optional) myCurve1.Symbol.Fill = new Fill( Color.White ); myCurve2.Symbol.Fill = new Fill( Color.White ); diffCurve.Line.Width = 2.0f; //diffCurve.Symbol.Fill = new Fill( Color.White ); myPane.Title.Text = "Interpolated Data Curve"; myPane.XAxis.Title.Text = "Period"; myPane.YAxis.Title.Text = "Response"; myPane.Legend.FontSpec.Size = 14; myPane.Fill = new Fill( Color.WhiteSmoke, Color.Lavender, 0F ); myPane.Chart.Fill = new Fill( Color.FromArgb( 255, 255, 245 ), Color.FromArgb( 255, 255, 190 ), 90F ); XDate xx = new XDate( 2007, 11, 9 ); XDate x2 = new XDate( 2007, 11, 9 ); XDate x3 = new XDate( 2007, 11, 9, 1, 1, 1 ); object junk = new object(); int i1 = xx.CompareTo( xx ); int i2 = xx.CompareTo( x2 ); int i3 = xx.CompareTo( x3 ); int i4 = x2.CompareTo( xx ); int i5 = x2.CompareTo( x3 ); int i6 = x3.CompareTo( x2 ); int i7 = x3.CompareTo( junk ); z1.IsAntiAlias = true; z1.AxisChange(); }
private void hScrollBar1_ValueChanged(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; XDate startx = new XDate(_firstDate.Year, _firstDate.Month, _firstDate.Day, _firstDate.Hour, _firstDate.Minute, _firstDate.Second); XDate endx = new XDate(startx); startx.AddMinutes(hScrollBar1.Value*_minutesPage); endx.AddMinutes((hScrollBar1.Value + 1)*_minutesPage); for (int i = 0; i < zedGraphControl1.MasterPane.PaneList.Count; i++) { zedGraphControl1.MasterPane[i].XAxis.Scale.Min = (double)startx; zedGraphControl1.MasterPane[i].XAxis.Scale.Max = (double)endx; } int pixelunits = (int)Math.Ceiling((double)(hScrollBar1.Width - 130) / hScrollBar1.Maximum); lbScrollTime.Location = new Point(hScrollBar1.Left + pixelunits* hScrollBar1.Value,lbScrollTime.Location.Y); lbScrollTime.Text = String.Format("{0}-{1}", startx.DateTime.ToShortTimeString(), endx.DateTime.ToShortTimeString()); if (_isAdaptingPointSize) SetPointSize(); zedGraphControl1.AxisChange(); zedGraphControl1.Refresh(); this.Cursor = Cursors.Default; }
private void CreateGraph_Gantt( ZedGraphControl zg1 ) { GraphPane myPane = zg1.GraphPane; // Setup the titles myPane.Title.Text = "Gantt Chart"; myPane.XAxis.Title.Text = "Date"; myPane.YAxis.Title.Text = "Project"; // XAxis is Date type myPane.XAxis.Type = AxisType.Date; // Y Axis is Text type (ordinal) myPane.YAxis.Type = AxisType.Text; // Bars will be horizontal myPane.BarSettings.Base = BarBase.Y; // Set the Y axis text labels string[] labels = { "Project 1", "Project 2" }; myPane.YAxis.Scale.TextLabels = labels; myPane.YAxis.MajorTic.IsBetweenLabels = true; // First, define all the bars that you want to be red PointPairList ppl = new PointPairList(); XDate start = new XDate( 2005, 10, 31 ); XDate end = new XDate( 2005, 11, 15 ); // x is start of bar, y is project number, z is end of bar // Define this first one using start/end variables for illustration ppl.Add( start, 1.0, end ); // add another red bar, assigned to project 2 // Didn't use start/end variables here, but it's the same concept ppl.Add( new XDate( 2005, 12, 16 ), 2.0, new XDate( 2005, 12, 31 ) ); HiLowBarItem myBar = myPane.AddHiLowBar( "job 1", ppl, Color.Red ); // This tells the bar that we want to manually define the Y position // Y is AxisType.Text, which is ordinal, so a Y value of 1.0 goes with the first label, // 2.0 with the second, etc. myBar.IsOverrideOrdinal = true; myBar.Bar.Fill = new Fill( Color.Red, Color.White, Color.Red, 90.0f ); // This size is the width of the bar // myBar.Bar.Size = 20f; // Now, define all the bars that you want to be Green ppl = new PointPairList(); ppl.Add( new XDate( 2005, 11, 16 ), 2.0, new XDate( 2005, 11, 26 ) ); myBar = myPane.AddHiLowBar( "job 2", ppl, Color.Green ); myBar.IsOverrideOrdinal = true; myBar.Bar.Fill = new Fill( Color.Green, Color.White, Color.Green, 90.0f ); // myBar.Bar.Size = 20f; // Define all the bars that you want to be blue ppl = new PointPairList(); ppl.Add( new XDate( 2005, 11, 27 ), 1.0, new XDate( 2005, 12, 15 ) ); myBar = myPane.AddHiLowBar( "job 3", ppl, Color.Blue ); myBar.IsOverrideOrdinal = true; myBar.Bar.Fill = new Fill( Color.Blue, Color.White, Color.Blue, 90.0f ); // myBar.Bar.Size = 20f; myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f ); myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f ); zg1.AxisChange(); }
private void SetTimes() { lbFirstDate.Text = _firstDate.ToString(); lbSecondDate.Text = _lastDate.ToString(); lbScrollTime.Text = _firstDate.ToString(); TimeSpan ts = _lastDate - _firstDate; #region DETERMINE PAGING SIZE BASED ON TOTAL TIMESPAN OF DATA if (ts.TotalHours > 3)//4 or more hours of data _minutesPage = 60; else if (ts.TotalMinutes > 60)//between 1-4 hours of data _minutesPage = 10; else if (ts.TotalMinutes > 15) _minutesPage = 5; //between 15-60 minutes of data else _minutesPage = 1; #endregion hScrollBar1.LargeChange = 1; hScrollBar1.SmallChange = 1; hScrollBar1.Maximum = (int)Math.Ceiling(ts.TotalMinutes / _minutesPage); //XDate startx = new XDate(_firstDate.AddMinutes(-padding)); XDate startx = new XDate(_firstDate); //XDate endx = new XDate(_lastDate.AddMinutes(padding)); XDate endx = new XDate(_lastDate); for (int i = 0; i < zedGraphControl1.MasterPane.PaneList.Count; i++) { zedGraphControl1.MasterPane[i].XAxis.Scale.Min = (double)startx; zedGraphControl1.MasterPane[i].XAxis.Scale.Max = (double)endx; } zedGraphControl1.AxisChange(); zedGraphControl1.Refresh(); }
private void CreateGraph_Gantt2( ZedGraphControl zgc ) { GraphPane myPane = zgc.MasterPane[0]; // Set the title and axis labels myPane.Title.Text = "Tony's TimeLine"; myPane.XAxis.Title.Text = "Time"; myPane.YAxis.Title.Text = "Case"; string[] str = { "Tony", "Alex", "Judy", "Kenny" }; // Create points for three BarItems PointPairList list1 = new PointPairList(); PointPairList list2 = new PointPairList(); PointPairList list3 = new PointPairList(); // Use random data values Random rand = new Random(); double xStart1 = new XDate( 2007, 1, 1 ); double xStart2 = new XDate( 2007, 2, 2 ); double xStart3 = new XDate( 2007, 3, 3 ); double xEnd1, xEnd2, xEnd3; for ( int i = 1; i < 5; i++ ) { double y = (double) i; // define the end of each bar (up to 50 days long) xEnd1 = xStart1 + rand.NextDouble() * 40.0 + 10.0; xEnd2 = xStart2 + rand.NextDouble() * 40.0 + 10.0; xEnd3 = xStart3 + rand.NextDouble() * 40.0 + 10.0; list1.Add( xStart1, y, xEnd1 ); list2.Add( xStart2, y, xEnd2 ); list3.Add( xStart3, y, xEnd3 ); // Next bar starts 10 to 30 days later xStart1 = xEnd1 + rand.NextDouble() * 20.0 + 10.0; xStart2 = xEnd2 + rand.NextDouble() * 20.0 + 10.0; xStart3 = xEnd3 + rand.NextDouble() * 20.0 + 10.0; } // Create the three BarItems, change the fill properties so the angle is at 90 // degrees for horizontal bars HiLowBarItem bar1 = myPane.AddHiLowBar( "File No", list1, Color.Red ); bar1.Bar.Fill = new Fill( Color.Red, Color.White, Color.Red, 90 ); HiLowBarItem bar2 = myPane.AddHiLowBar( "IELTS Notice", list2, Color.Blue ); bar2.Bar.Fill = new Fill( Color.Blue, Color.White, Color.Blue, 90 ); HiLowBarItem bar3 = myPane.AddHiLowBar( "Pre Visa", list3, Color.Green ); bar3.Bar.Fill = new Fill( Color.Green, Color.White, Color.Green, 90 ); // Set the XAxis to Text type myPane.XAxis.Type = AxisType.Date; // Set the YAxis labels myPane.YAxis.Type = AxisType.Text; myPane.YAxis.Scale.TextLabels = str; myPane.Border.IsVisible = false; // Set BarBase to the YAxis for horizontal bars myPane.BarSettings.Base = BarBase.Y; zgc.AxisChange(); }
private void Form_StockChart_Load(object sender, EventArgs e) { // Get a reference to the GraphPane instance in the ZedGraphControl GraphPane myPane = zg1.GraphPane; // Set the titles and axis labels myPane.Title.Text = this.Text = title; myPane.XAxis.Title.Text = "Date"; myPane.YAxis.Title.Text = "Close price"; foreach (Model_ShockChart eachModel in stockLineList) { // Make up some data points based on the Sine function StockPointList spl = new StockPointList(); foreach (Tick eachTick in eachModel.stock.priceList) { double x = new XDate(eachTick.Time); double open = ((NumericTick)eachTick).open; double close = ((NumericTick)eachTick).close; double high = ((NumericTick)eachTick).high; double low = ((NumericTick)eachTick).low; double vol = 0.0; try { vol = double.Parse(((NumericTick)eachTick).volume); } catch (Exception ex) { LogHelper.GetLogger(typeof(MainForm)).FullLog(ex.ToString(), "IGNORE"); } spl.Add(new StockPt(x, high, low, open, close, vol)); } // Generate a blue curve with circle symbols, and "Beta" in the legend myPane.AddCurve(eachModel.stock.stockCode + ".HK", spl, eachModel.color, SymbolType.None); } // JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick(baseStock.stockCode + ".HK", spl); // myCurve.Stick.IsAutoSize = true; // myCurve.Stick.Color = Color.Blue; // myCurve = myPane.AddCurve("Beta", list2, Color.Blue, SymbolType.Circle); // Fill the symbols with white // myCurve.Symbol.Fill = new Fill(Color.White); // Associate this curve with the Y2 axis // myCurve.IsY2Axis = true; // Show the x axis grid myPane.XAxis.MajorGrid.IsVisible = true; // Make the Y axis scale red // myPane.YAxis.Scale.FontSpec.FontColor = Color.Red; // myPane.YAxis.Title.FontSpec.FontColor = Color.Red; // turn off the opposite tics so the Y tics don't show up on the Y2 axis myPane.YAxis.MajorTic.IsOpposite = false; myPane.YAxis.MinorTic.IsOpposite = false; // Don't display the Y zero line myPane.YAxis.MajorGrid.IsZeroLine = false; // Align the Y axis labels so they are flush to the axis myPane.YAxis.Scale.Align = AlignP.Inside; // Manually set the axis range // myPane.YAxis.Scale.Min = -30; // myPane.YAxis.Scale.Max = 30; // myPane.XAxis.Scale.Max = baseStock.priceList.Count; // Set the XAxis to date type myPane.XAxis.Type = AxisType.Date; // Enable the Y2 axis display // myPane.Y2Axis.IsVisible = true; // Make the Y2 axis scale blue // myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Blue; // myPane.Y2Axis.Title.FontSpec.FontColor = Color.Blue; // turn off the opposite tics so the Y2 tics don't show up on the Y axis // myPane.Y2Axis.MajorTic.IsOpposite = false; // myPane.Y2Axis.MinorTic.IsOpposite = false; // Display the Y2 axis grid lines // myPane.Y2Axis.MajorGrid.IsVisible = true; // Align the Y2 axis labels so they are flush to the axis // myPane.Y2Axis.Scale.Align = AlignP.Inside; // Fill the axis background with a gradient myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f); // Add a text box with instructions // TextObj text = new TextObj( // "Zoom: left mouse & drag\nPan: middle mouse & drag\nContext Menu: right mouse", // 0.05f, 0.95f, CoordType.ChartFraction, AlignH.Left, AlignV.Bottom); // text.FontSpec.StringAlignment = StringAlignment.Near; // myPane.GraphObjList.Add(text); // Enable scrollbars if needed zg1.IsShowHScrollBar = true; zg1.IsShowVScrollBar = true; zg1.IsAutoScrollRange = true; zg1.IsScrollY2 = true; // OPTIONAL: Show tooltips when the mouse hovers over a point zg1.IsShowPointValues = true; zg1.PointValueEvent += new ZedGraphControl.PointValueHandler(MyPointValueHandler); // OPTIONAL: Add a custom context menu item // zg1.ContextMenuBuilder += new ZedGraphControl.ContextMenuBuilderEventHandler(MyContextMenuBuilder); // OPTIONAL: Handle the Zoom Event zg1.ZoomEvent += new ZedGraphControl.ZoomEventHandler(MyZoomEvent); // Size the control to fit the window // SetSize(); // Tell ZedGraph to calculate the axis ranges // Note that you MUST call this after enabling IsAutoScrollRange, since AxisChange() sets // up the proper scrolling parameters zg1.AxisChange(); // Make sure the Graph gets redrawn zg1.Invalidate(); }
// Call this method from the Form_Load method, passing your ZedGraphControl public void CreateGraph_JapaneseCandleStickDemo( ZedGraphControl zgc ) { GraphPane myPane = zgc.GraphPane; // Set the title and axis labels myPane.Title.Text = "Japanese Candlestick Chart Demo"; myPane.XAxis.Title.Text = "Trading Date"; myPane.YAxis.Title.Text = "Share Price, $US"; StockPointList spl = new StockPointList(); Random rand = new Random(); // First day is jan 1st XDate xDate = new XDate( 2006, 1, 1 ); double open = 50.0; for ( int i = 0; i < 50; i++ ) { double x = xDate.XLDate; double close = open + rand.NextDouble() * 10.0 - 5.0; double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0; double low = Math.Min( open, close ) - rand.NextDouble() * 5.0; StockPt pt = new StockPt( x, hi, low, open, close, 100000 ); spl.Add( pt ); open = close; // Advance one day //xDate.AddDays( 1 + 0.4 * rand.NextDouble() - 0.2 ); xDate.AddDays( 1 ); // but skip the weekends if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 ) xDate.AddDays( 2.0 ); } JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick( "trades", spl ); myCurve.Stick.IsAutoSize = true; myCurve.Stick.Color = Color.Blue; // Use DateAsOrdinal to skip weekend gaps myPane.XAxis.Type = AxisType.DateAsOrdinal; //myPane.XAxis.Type = AxisType.Date; //myPane.XAxis.Scale.Min = new XDate( 2006, 1, 1 ); // pretty it up a little myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f ); myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f ); // Tell ZedGraph to calculate the axis ranges zgc.AxisChange(); zgc.Invalidate(); }
/// <summary> /// The Copy Constructor /// </summary> /// <param name="rhs">The GraphPane object from which to copy</param> public XDate( XDate rhs ) { xlDate = rhs.xlDate; }
// Traditional Open-High-Low-Close Bar chart private void CreateGraph_OHLCBar( ZedGraphControl z1 ) { GraphPane myPane = z1.GraphPane; myPane.Title.Text = "OHLC Chart Demo"; myPane.XAxis.Title.Text = "Trading Date"; myPane.YAxis.Title.Text = "Share Price, $US"; StockPointList spl = new StockPointList(); Random rand = new Random(); // First day is feb 1st XDate xDate = new XDate( 2006, 2, 1 ); double open = 50.0; for ( int i = 0; i < 20; i++ ) { double x = xDate.XLDate; double close = open + rand.NextDouble() * 10.0 - 5.0; double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0; double low = Math.Min( open, close ) - rand.NextDouble() * 5.0; StockPt pt = new StockPt( x, hi, low, open, close, 100000 ); spl.Add( pt ); open = close; // Advance one day xDate.AddDays( 1.0 ); // but skip the weekends if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 ) xDate.AddDays( 2.0 ); } //OHLCBarItem myCurve = myPane.AddOHLCBar( "trades", spl, Color.Black ); OHLCBarItem myCurve = myPane.AddOHLCBar( "trades", spl, Color.Blue ); //myCurve.Bar.Size = 20; myCurve.Bar.IsAutoSize = true; //myCurve.Bar.PenWidth = 2; //myCurve.Bar.IsOpenCloseVisible = false; Fill fill = new Fill( Color.Red, Color.Yellow, Color.Blue ); fill.RangeMin = 40; fill.RangeMax = 70; fill.Type = FillType.GradientByY; myCurve.Bar.GradientFill = fill; // Use DateAsOrdinal to skip weekend gaps myPane.XAxis.Type = AxisType.DateAsOrdinal; //myPane.XAxis.Type = AxisType.Date; //myPane.XAxis.Scale.MajorStep = 1.0; // pretty it up a little myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f ); myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f ); //BoxObj box = new BoxObj( 4, 60, 5, 50000 ); //myPane.GraphObjList.Add( box ); // Tell ZedGraph to calculate the axis ranges z1.AxisChange(); z1.Invalidate(); }
/// <summary> /// The Copy Constructor /// </summary> /// <param name="rhs">The GraphPane object from which to copy</param> public XDate( XDate rhs ) { _xlDate = rhs._xlDate; }
// OHLC Bar Test private void CreateGraph_OHLCBarTest( ZedGraphControl z1 ) { GraphPane myPane = z1.GraphPane; myPane.Title.Text = "OHLC Chart Demo"; myPane.XAxis.Title.Text = "Trading Date"; myPane.YAxis.Title.Text = "Share Price, $US"; StockPointList spl = new StockPointList(); Random rand = new Random(); // First day is jan 1st XDate xDate = new XDate( 2006, 1, 1 ); double open = 50.0; for ( int i = 0; i < 50; i++ ) { double x = xDate.XLDate; double close = open + rand.NextDouble() * 10.0 - 5.0; double hi = Math.Max( open, close ) + rand.NextDouble() * 5.0; double low = Math.Min( open, close ) - rand.NextDouble() * 5.0; StockPt pt = new StockPt( x, hi, low, open, close, 100000 ); spl.Add( pt ); open = close; // Advance one day //xDate.AddMinutes( 1.0 ); xDate.AddDays( 1.0 ); // but skip the weekends //if ( XDate.XLDateToDayOfWeek( xDate.XLDate ) == 6 ) // xDate.AddMinutes( 2.0 ); } OHLCBarItem myCurve = myPane.AddOHLCBar( "trades", spl, Color.Blue); //myCurve.Bar.IsAutoSize = true; myCurve.Bar.Color = Color.Blue; // Use DateAsOrdinal to skip weekend gaps //myPane.XAxis.Type = AxisType.DateAsOrdinal; myPane.XAxis.Type = AxisType.Date; //myPane.XAxis.Scale.Min = new XDate( 2006, 1, 1 ); // pretty it up a little myPane.Chart.Fill = new Fill( Color.White, Color.LightGoldenrodYellow, 45.0f ); myPane.Fill = new Fill( Color.White, Color.FromArgb( 220, 220, 255 ), 45.0f ); // Tell ZedGraph to calculate the axis ranges z1.AxisChange(); z1.Invalidate(); //z1.PointValueEvent += new ZedGraphControl.PointValueHandler( z1_PointValueEvent ); }