Пример #1
0
        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();
        }