ArcGISPortalViewer.Popup.Primitives.Charting.LineChart.GenerateDataPoints C# (CSharp) Method

GenerateDataPoints() private method

private GenerateDataPoints ( double>.IDictionary data, Range dataRange ) : void
data double>.IDictionary
dataRange Range
return void
        private void GenerateDataPoints(IDictionary<string, double> data, Range dataRange)
        {
            int count = data.Count;

            // Project the data in order to get the points in percent of the drawing space (rectangle 1*1)
            var points = data.Select((kvp, ind) => new { x = (2.0 * ind + 1.0) / (2.0 * count), y = 1.0 - dataRange.Fraction(kvp.Value)});

            // Generate the lines from point to point
            var firstPoint = points.First();
            PathFigure pathFigure = new PathFigure { IsClosed = false, StartPoint = new Point(firstPoint.x, firstPoint.y) };
            foreach (var point in points.Skip(1))
            {
                pathFigure.Segments.Add(new LineSegment {Point = new Point(point.x, point.y)});
            }

            //Add these two empty line segments to force the drawing to stretch properly
            PathFigure pathFigure2 = new PathFigure { StartPoint = new Point(0, 0) };
            pathFigure2.Segments.Add(new LineSegment { Point = new Point(0, 0) });
            PathFigure pathFigure3 = new PathFigure { StartPoint = new Point(1, 1) };
            pathFigure3.Segments.Add(new LineSegment { Point = new Point(1, 1) });

            PathGeometry pathGeometry = new PathGeometry();
            pathGeometry.Figures.Add(pathFigure2);
            pathGeometry.Figures.Add(pathFigure3);
            pathGeometry.Figures.Add(pathFigure);
            Path path = new Path
            {
                Stretch = Stretch.Fill, // stretch the polyline to fill the chart drawing space
                Stroke = GetColorByIndex(0),
                StrokeThickness = 2,
                StrokeLineJoin = PenLineJoin.Round,
                Data = pathGeometry,
                Margin = new Thickness(-1,-1,-1,-1) // half of strokeThickness
            };
            _series.Children.Add(path);

            // Add a new grid for the points
            Grid pointsGrid = new Grid();
            _series.Children.Add(pointsGrid);

            // Generate the points
            foreach (var kvp in data)
            {
                GenerateDataPoint(pointsGrid, kvp, dataRange);
            }
        }