public void GetBarWidth_OrdinalAxisWeeklyValues_3Pixels()
        {
            GraphPane myPane = new GraphPane();

            myPane.Rect       = new RectangleF(0, 0, 640f, 480f);
            myPane.XAxis.Type = AxisType.DateAsOrdinal;

            StockPointList spl     = CreateStockPointList(60 * 24 * 7);
            OHLCBarItem    myCurve = myPane.AddOHLCBar("trades", spl, Color.Black);

            AxisChangeAndDraw(myPane);

            Assert.That(myCurve.Bar.GetBarWidth(myPane, myPane.XAxis, 1.0f), Is.EqualTo(3f));
        }
Beispiel #2
0
        public void GetBarWidth_NonOrdinalAxisIntradayValues_2Pixels()
        {
            GraphPane myPane = new GraphPane();
            myPane.Rect = new RectangleF(0, 0, 640f, 480f);
            myPane.XAxis.Type = AxisType.Date;

            StockPointList spl = CreateStockPointList(5);

            OHLCBarItem myCurve = myPane.AddOHLCBar("trades", spl, Color.Black);

            AxisChangeAndDraw(myPane);

            Assert.That(myCurve.Bar.GetBarWidth(myPane, myPane.XAxis, 1.0f), Is.EqualTo(2f));
        }
Beispiel #3
0
        /// <summary>
        /// Draws the Open High Low Close graph.
        /// </summary>
        /// <param name="data">The stock points to plot.</param>
        /// <param name="control">The control to plot on.</param>
        public void DrawOHLCGraph(ref StockPoints data, ref ZedGraph.ZedGraphControl control)
        {
            StockPointList pointList = new StockPointList();
            XDate date = new XDate();
            foreach (StockPoint s in data)
            {
                date = new XDate(s.PointDateTime.Year, s.PointDateTime.Month, s.PointDateTime.Day, s.PointDateTime.Hour, s.PointDateTime.Minute, 0);
                StockPt p = new StockPt(date.XLDate, s.High, s.Low, s.Open, s.Close, s.Volume);
                pointList.Add(p);
            }

            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;

            MasterPane masterPane = control.MasterPane;
            masterPane.Margin.All = 10;
            masterPane.InnerPaneGap = 5;

            GraphPane ohlcPane = new GraphPane(new Rectangle(10, 10, 10, 10), "OHLC", "Time", "Price");

            ohlcPane.IsBoundedRanges = true;

            OHLCBarItem bar = ohlcPane.AddOHLCBar("Price", pointList, Color.Empty);
            bar.Bar.GradientFill = myFill;
            bar.Bar.IsAutoSize = true;
            bar.Bar.Size = 5;

            ohlcPane.Title.Text = "OHLC Graph";
            ohlcPane.XAxis.Type = AxisType.DateAsOrdinal;
            ohlcPane.XAxis.Title.Text = "Date";
            ohlcPane.YAxis.Title.Text = "Price";
            ohlcPane.Margin.All = 0;
            ohlcPane.Margin.Top = 10;
            ohlcPane.YAxis.MinSpace = 10;
            ohlcPane.Y2Axis.MinSpace = 10;
            ohlcPane.AxisChange();

            masterPane.Add(ohlcPane);

            control.IsShowHScrollBar = true;
            control.ScrollMinX = 0;
            control.ScrollMaxX = data.Count;
            control.GraphPane.XAxis.Scale.Max = data.Count;
            if (data.Count >= 99)
            {
                control.GraphPane.XAxis.Scale.Min = data.Count - 99;
            }
            else
            {
                control.GraphPane.XAxis.Scale.Min = 0;
            }

            using (Graphics g = control.CreateGraphics())
            {
                masterPane.SetLayout(g, PaneLayout.SingleColumn);
                masterPane.AxisChange(g);

                // Synchronize the Axes
                //// g.Dispose();
            }
        }