/// <summary>
        /// Updates each point.
        /// </summary>
        /// <param name="dataPoint">The data point to update.</param>
        protected override void UpdateDataPoint(DataPoint dataPoint)
        {
            if (SeriesHost == null || PlotArea == null)
            {
                return;
            }

            object         category        = dataPoint.IndependentValue ?? (this.ActiveDataPoints.IndexOf(dataPoint) + 1);
            Range <double> coordinateRange = ActualIndependentCategoryAxis.GetPlotAreaCoordinateRange(category);

            if (!coordinateRange.HasData)
            {
                return;
            }

            double plotAreaHeight = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum);
            IEnumerable <ColumnSeries> columnSeries = SeriesHost.Series.OfType <ColumnSeries>().Where(series => series.ActualIndependentCategoryAxis == ActualIndependentCategoryAxis);
            int    numberOfSeries       = columnSeries.Count();
            double coordinateRangeWidth = (coordinateRange.Maximum - coordinateRange.Minimum);
            double segmentWidth         = coordinateRangeWidth * 0.8;
            double columnWidth          = segmentWidth / numberOfSeries;
            int    seriesIndex          = columnSeries.IndexOf(this);

            double dataPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(ValueHelper.ToDouble(dataPoint.ActualDependentValue));
            double zeroPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(0);

            double offset     = seriesIndex * Math.Round(columnWidth) + coordinateRangeWidth * 0.1;
            double dataPointX = coordinateRange.Minimum + offset;

            if (_categoriesWithMultipleDataPoints.ContainsKey(category))
            {
                // Multiple DataPoints share this category; offset and overlap them appropriately
                IGrouping <object, DataPoint> categoryGrouping = _categoriesWithMultipleDataPoints[category];
                int index = categoryGrouping.IndexOf(dataPoint);
                dataPointX  += (index * (columnWidth * 0.2)) / (categoryGrouping.Count() - 1);
                columnWidth *= 0.8;
                Canvas.SetZIndex(dataPoint, -index);
            }

            if (!double.IsNaN(dataPointY) && !double.IsNaN(dataPointX) && !double.IsNaN(zeroPointY))
            {
                double left  = Math.Round(dataPointX);
                double width = Math.Round(columnWidth);

                double top    = Math.Round(plotAreaHeight - Math.Max(dataPointY, zeroPointY) + 0.5);
                double bottom = Math.Round(plotAreaHeight - Math.Min(dataPointY, zeroPointY) + 0.5);
                double height = bottom - top + 1;

                Canvas.SetLeft(dataPoint, left);
                Canvas.SetTop(dataPoint, top);
                dataPoint.Width  = width;
                dataPoint.Height = height;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates each point.
        /// </summary>
        /// <param name="dataPoint">The data point to update.</param>
        protected override void UpdateDataPoint(DataPoint dataPoint)
        {
            if (SeriesHost == null || PlotArea == null)
            {
                return;
            }

            object         category        = dataPoint.IndependentValue ?? (this.ActiveDataPoints.IndexOf(dataPoint) + 1);
            Range <double> coordinateRange = ActualIndependentCategoryAxis.GetPlotAreaCoordinateRange(category);

            if (!coordinateRange.HasData)
            {
                return;
            }

            IEnumerable <BarSeries> barSeries = SeriesHost.Series.OfType <BarSeries>().Where(series => series.ActualIndependentCategoryAxis == ActualIndependentCategoryAxis);
            int    numberOfSeries             = barSeries.Count();
            double coordinateRangeHeight      = (coordinateRange.Maximum - coordinateRange.Minimum);
            double segmentHeight = coordinateRangeHeight * 0.8;
            double barHeight     = segmentHeight / numberOfSeries;
            int    seriesIndex   = barSeries.IndexOf(this);

            double dataPointX = ActualDependentRangeAxis.GetPlotAreaCoordinate(ValueHelper.ToDouble(dataPoint.ActualDependentValue));
            double zeroPointX = ActualDependentRangeAxis.GetPlotAreaCoordinate(0);

            double offset     = seriesIndex * Math.Round(barHeight) + coordinateRangeHeight * 0.1;
            double dataPointY = coordinateRange.Minimum + offset;

            if (_categoriesWithMultipleDataPoints.ContainsKey(category))
            {
                // Multiple DataPoints share this category; offset and overlap them appropriately
                IGrouping <object, DataPoint> categoryGrouping = _categoriesWithMultipleDataPoints[category];
                int index = categoryGrouping.IndexOf(dataPoint);
                dataPointY += (index * (barHeight * 0.2)) / (categoryGrouping.Count() - 1);
                barHeight  *= 0.8;
                Canvas.SetZIndex(dataPoint, -index);
            }

            if (ValueHelper.CanGraph(dataPointX) && ValueHelper.CanGraph(dataPointY) && ValueHelper.CanGraph(zeroPointX))
            {
                double top    = Math.Round(dataPointY);
                double height = Math.Round(barHeight);

                double left  = Math.Round(Math.Min(dataPointX, zeroPointX) - 0.5);
                double right = Math.Round(Math.Max(dataPointX, zeroPointX) - 0.5);
                double width = right - left + 1;

                Canvas.SetLeft(dataPoint, left);
                Canvas.SetTop(dataPoint, top);
                dataPoint.Width  = width;
                dataPoint.Height = height;
            }
        }