Ejemplo n.º 1
0
        public static LineAnnotation CreateChartLineAnnotation(IDataSeries series, DateTime date1, IComparable value1, DateTime date2, IComparable value2)
        {
            var startIndex = series.FindIndex(date1, SearchMode.Nearest);
            var endIndex   = series.FindIndex(date2, SearchMode.Nearest);

            // Would be good to use ((ICategoryCoordinateCalculator)surface.XAxis.GetCurrentCoordinateCalculator()).TransformDataToIndex(date1) but how to get the surface?
            return(new LineAnnotation
            {
                X1 = date1 <(DateTime)series.XMin || date1> (DateTime) series.XMax ? (IComparable)date1 : startIndex,
                X2 = date2 <(DateTime)series.XMin || date2> (DateTime) series.XMax ? (IComparable)date2 : endIndex,
                Y1 = value1,
                Y2 = value2
            });
        }
Ejemplo n.º 2
0
        private static void AddLineAnnotations(
            List <DatePrice> prices, IDataSeries series, AnnotationCollection annotations, Color colour)
        {
            int?     startIndex   = null;
            DateTime?startDate    = null;
            decimal? currentPrice = null;

            foreach (var p in prices)
            {
                if (p.Price != currentPrice)
                {
                    // Price changed
                    if (currentPrice != null && startIndex != null)
                    {
                        var endIndex = series.FindIndex(p.Date.ToLocalTime(), SearchMode.Nearest);

                        if (endIndex == startIndex.Value)
                        {
                            endIndex++;
                        }

                        var brush = new SolidColorBrush(colour)
                        {
                            Opacity = 0.3
                        };
                        var annotation = new LineAnnotation
                        {
                            X1     = startDate,            //startIndex.Value,
                            X2     = p.Date.ToLocalTime(), //endIndex,
                            Y1     = currentPrice.Value,
                            Y2     = currentPrice.Value,
                            Stroke = brush
                        };

                        annotations.Add(annotation);
                    }

                    startIndex   = series.FindIndex(p.Date.ToLocalTime(), SearchMode.Nearest);
                    startDate    = p.Date.ToLocalTime();
                    currentPrice = p.Price;
                }
            }
        }
Ejemplo n.º 3
0
        public static void AddHorizontalLine(decimal price, DateTime start, DateTime end, IDataSeries dataSeries,
                                             AnnotationCollection annotations, Trade trade, Color colour, bool extendLeftAndRight = false,
                                             bool extendRightIfZeroLength = false, DoubleCollection strokeDashArray = null)
        {
            var dateStartIndex = dataSeries.FindIndex(start, SearchMode.RoundDown);
            var dateEndIndex   = dataSeries.FindIndex(end, SearchMode.RoundUp);

            if (extendLeftAndRight)
            {
                dateStartIndex -= 4;
            }
            if (dateStartIndex < 0)
            {
                dateStartIndex = 0;
            }
            if (extendLeftAndRight)
            {
                dateEndIndex += 4;
            }

            if (extendRightIfZeroLength && dateStartIndex == dateEndIndex)
            {
                dateEndIndex++;
            }

            var lineAnnotation = new LineAnnotation
            {
                DataContext     = trade,
                X1              = dateStartIndex,
                Y1              = price,
                X2              = dateEndIndex,
                Y2              = price,
                StrokeThickness = 3,
                Opacity         = 0.8,
                Stroke          = new SolidColorBrush(colour)
            };

            if (strokeDashArray != null)
            {
                lineAnnotation.StrokeDashArray = strokeDashArray;
            }
            annotations.Add(lineAnnotation);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Because SciChart messes up lines that use DateTime but are not correctly on a axis point (the line appears to move
 /// while scrolling) use index instead of DateTime apart from when the DateTime is after the last data point - in this
 /// situation use DateTime, otherwise FindIndex will just return the latest chart point.
 /// </summary>
 /// <param name="data"></param>
 /// <param name="date"></param>
 /// <param name="positionType"></param>
 /// <returns></returns>
 public static IComparable FindChartPosition(IDataSeries data, DateTime date, ref PositionType?positionType)
 {
     if ((positionType != null && positionType == PositionType.DateTime) || date > (DateTime)data.XMax)
     {
         positionType = PositionType.DateTime;
         return(date);
     }
     else
     {
         positionType = PositionType.Int;
         return(data.FindIndex(date, SearchMode.Nearest));
     }
 }