示例#1
0
 /// <summary>
 /// The Copy Constructor
 /// </summary>
 /// <param name="rhs">The <see cref="CandleStickItem"/> object from which to copy</param>
 public CandleStickItem(CandleStickItem rhs)
     : base(rhs)
 {
     _stick = rhs._stick.Clone();
 }
 /// <summary>
 /// The Copy Constructor
 /// </summary>
 /// <param name="rhs">The <see cref="CandleStickItem"/> object from which to copy</param>
 public CandleStickItem(CandleStickItem rhs)
     : base(rhs)
 {
     _stick = rhs._stick.Clone();
 }
示例#3
0
        /// <summary>
        /// Draw all the <see cref="CandleStick"/>'s to the specified <see cref="Graphics"/>
        /// device as a candlestick at each defined point.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="curve">A <see cref="CandleStickItem"/> object representing the
        /// <see cref="CandleStick"/>'s to be drawn.</param>
        /// <param name="baseAxis">The <see cref="Axis"/> class instance that defines the base (independent)
        /// axis for the <see cref="CandleStick"/></param>
        /// <param name="valueAxis">The <see cref="Axis"/> class instance that defines the value (dependent)
        /// axis for the <see cref="CandleStick"/></param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and
        /// passed down by the parent <see cref="GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        public void Draw(Graphics g, GraphPane pane, CandleStickItem curve,
                         Axis baseAxis, Axis valueAxis, float scaleFactor)
        {
            //ValueHandler valueHandler = new ValueHandler( pane, false );

            float pixBase, pixHigh, pixLow, pixOpen, pixClose;

            if (curve.Points != null)
            {
                //float halfSize = _size * scaleFactor;
                float halfSize = GetBarWidth(pane, baseAxis, scaleFactor);

                using (var pen = new Pen(_color, _penWidth))
                {
                    // Loop over each defined point
                    for (int i = 0; i < curve.Points.Count; i++)
                    {
                        PointPair pt = curve.Points[i];
                        double date = pt.X;
                        double high = pt.Y;
                        double low = pt.Z;
                        double open = PointPair.Missing;
                        double close = PointPair.Missing;
                        if (pt is StockPt)
                        {
                            open = (pt as StockPt).Open;
                            close = (pt as StockPt).Close;
                        }

                        // Any value set to double max is invalid and should be skipped
                        // This is used for calculated values that are out of range, divide
                        //   by zero, etc.
                        // Also, any value <= zero on a log scale is invalid

                        if (!curve.Points[i].IsInvalid3D &&
                            (date > 0 || !baseAxis._scale.IsLog) &&
                            ((high > 0 && low > 0) || !valueAxis._scale.IsLog))
                        {
                            pixBase = baseAxis.Scale.Transform(curve.IsOverrideOrdinal, i, date);
                            pixHigh = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, i, high);
                            pixLow = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, i, low);
                            if (PointPair.IsValueInvalid(open))
                                pixOpen = Single.MaxValue;
                            else
                                pixOpen = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, i, open);

                            if (PointPair.IsValueInvalid(close))
                                pixClose = Single.MaxValue;
                            else
                                pixClose = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, i, close);

                            Draw(g, pane, baseAxis is XAxis, pixBase, pixHigh, pixLow, pixOpen,
                                 pixClose, halfSize, pen);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Draw all the <see cref="CandleStick"/>'s to the specified <see cref="Graphics"/>
        /// device as a candlestick at each defined point.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="curve">A <see cref="CandleStickItem"/> object representing the
        /// <see cref="CandleStick"/>'s to be drawn.</param>
        /// <param name="baseAxis">The <see cref="Axis"/> class instance that defines the base (independent)
        /// axis for the <see cref="CandleStick"/></param>
        /// <param name="valueAxis">The <see cref="Axis"/> class instance that defines the value (dependent)
        /// axis for the <see cref="CandleStick"/></param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and
        /// passed down by the parent <see cref="GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        public void Draw(Graphics g, GraphPane pane, CandleStickItem curve,
                         Axis baseAxis, Axis valueAxis, float scaleFactor)
        {
            //ValueHandler valueHandler = new ValueHandler( pane, false );

            float pixBase, pixHigh, pixLow, pixOpen, pixClose;

            if (curve.Points != null)
            {
                Pen pen = new Pen(_color, _penWidth);
                //float halfSize = _size * scaleFactor;
                float halfSize = GetBarWidth(pane, baseAxis, scaleFactor);

                // Loop over each defined point
                for (int i = 0; i < curve.Points.Count; i++)
                {
                    IPointPair pt    = curve.Points[i];
                    double     date  = pt.X;
                    double     high  = pt.Y;
                    double     low   = pt.Z;
                    double     open  = PointPair.Missing;
                    double     close = PointPair.Missing;
                    if (pt is StockPt)
                    {
                        open  = (pt as StockPt).Open;
                        close = (pt as StockPt).Close;
                    }

                    // Any value set to double max is invalid and should be skipped
                    // This is used for calculated values that are out of range, divide
                    //   by zero, etc.
                    // Also, any value <= zero on a log scale is invalid

                    if (!curve.Points[i].IsInvalid3D &&
                        (date > 0 || !baseAxis._scale.IsLog) &&
                        ((high > 0 && low > 0) || !valueAxis._scale.IsLog))
                    {
                        pixBase = baseAxis.Scale.Transform(curve.IsOverrideOrdinal, i, date);
                        pixHigh = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, i, high);
                        pixLow  = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, i, low);
                        if (PointPair.IsValueInvalid(open))
                        {
                            pixOpen = Single.MaxValue;
                        }
                        else
                        {
                            pixOpen = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, i, open);
                        }

                        if (PointPair.IsValueInvalid(close))
                        {
                            pixClose = Single.MaxValue;
                        }
                        else
                        {
                            pixClose = valueAxis.Scale.Transform(curve.IsOverrideOrdinal, i, close);
                        }

                        Draw(g, pane, baseAxis is XAxis, pixBase, pixHigh, pixLow, pixOpen,
                             pixClose, halfSize, pen);
                    }
                }
            }
        }
示例#5
0
        /// <summary>
        /// Add a candlestick graph (<see cref="CandleStickItem"/> object) to the plot with
        /// the given data points (<see cref="IPointList"/>) and properties.
        /// </summary>
        /// <remarks>
        /// This is simplified way to add curves without knowledge of the
        /// <see cref="CurveList"/> class.  An alternative is to use
        /// the <see cref="ZedGraph.CurveList" /> Add() method.
        /// Note that the <see cref="IPointList" />
        /// should contain <see cref="StockPt" /> objects instead of <see cref="PointPair" />
        /// objects in order to contain all the data values required for this curve type.
        /// </remarks>
        /// <param name="label">The text label (string) for the curve that will be
        /// used as a <see cref="Legend"/> entry.</param>
        /// <param name="points">A <see cref="IPointList"/> of double precision value pairs that define
        /// the X and Y values for this curve</param>
        /// <param name="color">The color to used for the curve line,
        /// symbols, etc.</param>
        /// <returns>A <see cref="CurveItem"/> class for the newly created curve.
        /// This can then be used to access all of the curve properties that
        /// are not defined as arguments to the
        /// <see cref="AddCandleStick(string,IPointList,Color)"/> method.</returns>
        public CandleStickItem AddCandleStick(string label, IPointList points, Color color)
        {
            var curve = new CandleStickItem(label, points, color);
            _curveList.Add(curve);

            return curve;
        }