示例#1
0
        /// <summary>
        /// Creates the segments of BarSeries.
        /// </summary>
        public override void CreateSegments()
        {
            double        x1, x2, y1, y2;
            List <double> xValues    = null;
            bool          isGrouping = (ActualXAxis is CategoryAxis && !(ActualXAxis as CategoryAxis).IsIndexed);

            if (isGrouping)
            {
                xValues = GroupedXValuesIndexes;
            }
            else
            {
                xValues = GetXValues();
            }
            DoubleRange sbsInfo = this.GetSideBySideInfo(this);
            double      median  = sbsInfo.Delta / 2;
            double      origin  = ActualXAxis != null ? ActualXAxis.Origin : 0;

            if (ActualXAxis != null && ActualXAxis.Origin == 0 && ActualYAxis is LogarithmicAxis &&
                (ActualYAxis as LogarithmicAxis).Minimum != null)
            {
                origin = (double)(ActualYAxis as LogarithmicAxis).Minimum;
            }
            if (this.ActualXValues != null)
            {
                if (isGrouping)
                {
                    int segmentCount = 0;
                    Segments.Clear();
                    Adornments.Count();
                    GroupedActualData.Clear();
                    for (int i = 0; i < DistinctValuesIndexes.Count; i++)
                    {
                        var list = (from index in DistinctValuesIndexes[i]
                                    where GroupedSeriesYValues[0].Count > index
                                    select new List <double> {
                            GroupedSeriesYValues[0][index], index
                        }).
                                   OrderByDescending(val => val[0]).ToList();
                        for (int j = 0; j < list.Count; j++)
                        {
                            var yValue = list[j][0];
                            x1 = i + sbsInfo.Start;
                            x2 = i + sbsInfo.End;
                            y1 = yValue;
                            y2 = origin; // setting origin value for column segment
                            GroupedActualData.Add(ActualData[(int)list[j][1]]);
                            BarSegment barSegment = new BarSegment(x1, y1, x2, y2, this)
                            {
                                Item = GroupedActualData[segmentCount]
                            };
                            barSegment.XData = xValues[segmentCount];
                            barSegment.YData = yValue;
                            Segments.Add(barSegment);
                            if (AdornmentsInfo != null)
                            {
                                if (this.AdornmentsInfo.AdornmentsPosition == AdornmentsPosition.Top)
                                {
                                    AddColumnAdornments(i, yValue, x1, y1, segmentCount, median);
                                }
                                else if (this.AdornmentsInfo.AdornmentsPosition == AdornmentsPosition.Bottom)
                                {
                                    AddColumnAdornments(i, yValue, x1, y2, segmentCount, median);
                                }
                                else
                                {
                                    AddColumnAdornments(i, yValue, x1, y1 + (y2 - y1) / 2, segmentCount, median);
                                }
                            }

                            segmentCount++;
                        }
                    }
                }
                else
                {
                    ClearUnUsedSegments(DataCount);
                    ClearUnUsedAdornments(DataCount);
                    for (int i = 0; i < DataCount; i++)
                    {
                        x1 = xValues[i] + sbsInfo.Start;
                        x2 = xValues[i] + sbsInfo.End;
                        y1 = YValues[i];
                        y2 = origin; // setting origin value for bar segment
                        if (i < Segments.Count)
                        {
                            (Segments[i]).SetData(x1, y1, x2, y2);
                            (Segments[i] as BarSegment).XData = xValues[i];
                            (Segments[i] as BarSegment).YData = YValues[i];
                            (Segments[i] as BarSegment).Item  = ActualData[i];
                            if (SegmentColorPath != null && !Segments[i].IsEmptySegmentInterior && ColorValues.Count > 0 && !Segments[i].IsSelectedSegment)
                            {
                                Segments[i].Interior = (Interior != null) ? Interior : ColorValues[i];
                            }
                        }
                        else
                        {
                            BarSegment barSegment = new BarSegment(x1, y1, x2, y2, this)
                            {
                                Item = ActualData[i]
                            };
                            barSegment.XData = xValues[i];
                            barSegment.YData = YValues[i];
                            Segments.Add(barSegment);
                        }

                        if (AdornmentsInfo != null)
                        {
                            if (this.AdornmentsInfo.AdornmentsPosition == AdornmentsPosition.Top)
                            {
                                AddColumnAdornments(xValues[i], YValues[i], x1, y1, i, median);
                            }
                            else if (this.AdornmentsInfo.AdornmentsPosition == AdornmentsPosition.Bottom)
                            {
                                AddColumnAdornments(xValues[i], YValues[i], x1, y2, i, median);
                            }
                            else
                            {
                                AddColumnAdornments(xValues[i], YValues[i], x1, y1 + (y2 - y1) / 2, i, median);
                            }
                        }
                    }
                }
            }

            if (ShowEmptyPoints)
            {
                UpdateEmptyPointSegments(xValues, true);
            }
        }