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(); }
/// <summary> /// Determine the value for any minor tic. /// </summary> /// <remarks> /// This method properly accounts for <see cref="IsLog"/>, <see cref="IsText"/>, /// and other axis format settings. /// </remarks> /// <param name="baseVal"> /// The value of the first major tic (floating point double). This tic value is the base /// reference for all tics (including minor ones). /// </param> /// <param name="iTic"> /// The major tic number (0 = first major tic). For log scales, this is the actual power of 10. /// </param> /// <returns> /// The specified minor tic value (floating point double). /// </returns> private double CalcMinorTicValue( double baseVal, int iTic ) { double[] dLogVal = { 0, 0.301029995663981, 0.477121254719662, 0.602059991327962, 0.698970004336019, 0.778151250383644, 0.845098040014257, 0.903089986991944, 0.954242509439325, 1 }; if ( this.IsDate ) // date scale { XDate xDate= new XDate( baseVal ); switch ( this.minorUnit ) { case DateUnit.Year: default: xDate.AddYears( (double) iTic * this.minorStep ); break; case DateUnit.Month: xDate.AddMonths( (double) iTic * this.minorStep ); break; case DateUnit.Day: xDate.AddDays( (double) iTic * this.minorStep ); break; case DateUnit.Hour: xDate.AddHours( (double) iTic * this.minorStep ); break; case DateUnit.Minute: xDate.AddMinutes( (double) iTic * this.minorStep ); break; case DateUnit.Second: xDate.AddSeconds( (double) iTic * this.minorStep ); break; } return xDate.XLDate; } else if ( this.IsLog ) // log scale { return baseVal + Math.Floor( (double) iTic / 9.0 ) + dLogVal[ ( iTic + 9 ) % 9 ]; } else // regular linear scale { return baseVal + (double) this.minorStep * (double) iTic; } }
/// <summary> /// Determine the value for any minor tic. /// </summary> /// <remarks> /// This method properly accounts for <see cref="Scale.IsLog"/>, <see cref="Scale.IsText"/>, /// and other axis format settings. /// </remarks> /// <param name="baseVal"> /// The value of the first major tic (floating point double). This tic value is the base /// reference for all tics (including minor ones). /// </param> /// <param name="iTic"> /// The major tic number (0 = first major tic). For log scales, this is the actual power of 10. /// </param> /// <returns> /// The specified minor tic value (floating point double). /// </returns> internal override double CalcMinorTicValue(double baseVal, int iTic) { XDate xDate = new XDate(baseVal); switch (_minorUnit) { case DateUnit.Year: default: xDate.AddYears((double) iTic*_minorStep); break; case DateUnit.Month: xDate.AddMonths((double) iTic*_minorStep); break; case DateUnit.Day: xDate.AddDays((double) iTic*_minorStep); break; case DateUnit.Hour: xDate.AddHours((double) iTic*_minorStep); break; case DateUnit.Minute: xDate.AddMinutes((double) iTic*_minorStep); break; case DateUnit.Second: xDate.AddSeconds((double) iTic*_minorStep); break; } return xDate.XLDate; }
/// <summary> /// Determine the value for any major tic. /// </summary> /// <remarks> /// This method properly accounts for <see cref="IsLog"/>, <see cref="IsText"/>, /// and other axis format settings. /// </remarks> /// <param name="baseVal"> /// The value of the first major tic (floating point double) /// </param> /// <param name="tic"> /// The major tic number (0 = first major tic). For log scales, this is the actual power of 10. /// </param> /// <returns> /// The specified major tic value (floating point double). /// </returns> private double CalcMajorTicValue( double baseVal, double tic ) { if ( this.IsDate ) // date scale { XDate xDate = new XDate( baseVal ); switch ( this.majorUnit ) { case DateUnit.Year: default: xDate.AddYears( tic * this.step ); break; case DateUnit.Month: xDate.AddMonths( tic * this.step ); break; case DateUnit.Day: xDate.AddDays( tic * this.step ); break; case DateUnit.Hour: xDate.AddHours( tic * this.step ); break; case DateUnit.Minute: xDate.AddMinutes( tic * this.step ); break; case DateUnit.Second: xDate.AddSeconds( tic * this.step ); break; } return xDate.XLDate; } else if ( this.IsLog ) // log scale { return baseVal + (double) tic; } else // regular linear scale { return baseVal + (double) this.step * tic; } }