Esempio n. 1
0
        /// <summary>
        /// This method updates a single data point.
        /// </summary>
        /// <param name="dataPoint">The data point to update.</param>
        protected override void UpdateDataPoint(DataPoint dataPoint)
        {
            StockBarDataPoint candlestickDataPoint = (StockBarDataPoint)dataPoint;

            Double PlotAreaHeight = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum);
            Double dataPointX     = ActualIndependentRangeAxis.GetPlotAreaCoordinate(ValueHelper.ToComparable(dataPoint.ActualIndependentValue));
            Double highPointY     = ActualDependentRangeAxis.GetPlotAreaCoordinate(candlestickDataPoint.High);
            Double lowPointY      = ActualDependentRangeAxis.GetPlotAreaCoordinate(candlestickDataPoint.Low);
            Double openPointY     = ActualDependentRangeAxis.GetPlotAreaCoordinate(candlestickDataPoint.Open);
            Double closePointY    = ActualDependentRangeAxis.GetPlotAreaCoordinate(candlestickDataPoint.Close);

            if (!singleBlockWidth.HasValue)
            {
                Range <Double> doubleRange = ActualIndependentRangeAxis.Range.ToDoubleRange();

                Double rangeLength = doubleRange.Maximum - doubleRange.Minimum;

                if (rangeLength > 0.0)
                {
                    singleBlockWidth = PlotArea.Width * 1.0 / rangeLength;

                    if (singleBlockWidth < 4.0)
                    {
                        singleBlockWidth = 4.0;
                    }
                }
                else
                {
                    singleBlockWidth = 4.0;
                }
            }

            if (ValueHelper.CanGraph(dataPointX))
            {
                candlestickDataPoint.Background = new SolidColorBrush(Colors.Transparent);

                dataPoint.Height = Math.Abs(highPointY - lowPointY);

                dataPoint.Width = singleBlockWidth.Value * 0.8;

                if (dataPoint.Width > 16.0)
                {
                    dataPoint.Width = 16.0;
                }

                candlestickDataPoint.UpdateBody(ActualDependentRangeAxis);

                //if (dataPoint.ActualWidth == 0.0 || dataPoint.ActualHeight == 0.0)
                {
                    dataPoint.UpdateLayout();
                }

                Canvas.SetLeft(dataPoint, Math.Round(dataPointX - (dataPoint.ActualWidth / 2)));

                Canvas.SetTop(dataPoint, Math.Round(PlotAreaHeight - highPointY));
            }
        }
Esempio n. 2
0
        protected override void PrepareDataPoint(DataPoint dataPoint, object dataContext)
        {
            base.PrepareDataPoint(dataPoint, dataContext);

            StockBarDataPoint candlestickDataPoint = (StockBarDataPoint)dataPoint;

            candlestickDataPoint.SetBinding(StockBarDataPoint.OpenProperty, OpenValueBinding);
            candlestickDataPoint.SetBinding(StockBarDataPoint.CloseProperty, CloseValueBinding);
            candlestickDataPoint.SetBinding(StockBarDataPoint.HighProperty, HighValueBinding);
            candlestickDataPoint.SetBinding(StockBarDataPoint.LowProperty, LowValueBinding);
        }