Ejemplo n.º 1
0
        public IList <DataPoint> ToChartDataSource()
        {
            if (XValues == null)
            {
                throw new InvalidOperationException("XValues is missing.");
            }
            if (YValues == null)
            {
                throw new InvalidOperationException("XValues is missing");
            }

            // Extract x values from XValues collection.
            var xValueExtractor = new DoubleValueExtractor
            {
                Collection = XValues,
                Culture    = Culture,
                ValuePath  = XValuePath,
            };
            var xValues = xValueExtractor.Extract();

            // Extract y values from YValues collection.
            var yValueExtractor = new DoubleValueExtractor
            {
                Collection = YValues,
                Culture    = Culture,
                ValuePath  = YValuePath,
            };
            var yValues = yValueExtractor.Extract();

            Debug.Assert(xValues.Count == yValues.Count, "Number of x values in data source does not match the number of y values?!");

            var chartDataSource    = new DataPointCollection();
            int index              = 0;
            int numberOfDataPoints = Math.Min(xValues.Count, yValues.Count);
            var xValuesEnumerator  = XValues.GetEnumerator();
            var yValuesEnumerator  = YValues.GetEnumerator();

            while (index < numberOfDataPoints)
            {
                xValuesEnumerator.MoveNext();
                yValuesEnumerator.MoveNext();
                var dataPoint = new DataPoint
                {
                    X           = xValues[index],
                    Y           = yValues[index],
                    DataContext = new CompositeData(xValuesEnumerator.Current, yValuesEnumerator.Current)
                };
                chartDataSource.Add(dataPoint);
                index++;
            }

            return(chartDataSource);
        }