Exemple #1
0
        /// <summary>
        /// Initializes all necessary data to draw all series for a column chart.
        /// </summary>
        internal void InitSeries()
        {
            ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;

            int seriesIndex = 0;

            foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            {
                sri.LineFormat = Converter.ToXPen(sri.series.lineFormat, XColors.Black, ChartRenderer.DefaultSeriesLineWidth);
                sri.FillFormat = Converter.ToXBrush(sri.series.fillFormat, ColumnColors.Item(seriesIndex++));

                sri.pointRendererInfos = new ColumnRendererInfo[sri.series.seriesElements.Count];
                for (int pointIdx = 0; pointIdx < sri.pointRendererInfos.Length; ++pointIdx)
                {
                    PointRendererInfo pri   = new ColumnRendererInfo();
                    Point             point = sri.series.seriesElements[pointIdx];
                    pri.point = point;
                    if (point != null)
                    {
                        pri.LineFormat = sri.LineFormat;
                        pri.FillFormat = sri.FillFormat;
                        if (point.lineFormat != null && !point.lineFormat.color.IsEmpty)
                        {
                            pri.LineFormat = Converter.ToXPen(point.lineFormat, sri.LineFormat);
                        }
                        if (point.fillFormat != null && !point.fillFormat.color.IsEmpty)
                        {
                            pri.FillFormat = new XSolidBrush(point.fillFormat.color);
                        }
                    }
                    sri.pointRendererInfos[pointIdx] = pri;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Determines the sum of the smallest and the largest stacked bar
        /// from all series of the chart.
        /// </summary>
        protected override void CalcYAxis(out double yMin, out double yMax)
        {
            yMin = double.MaxValue;
            yMax = double.MinValue;

            ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;

            int maxPoints = 0;

            foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            {
                maxPoints = Math.Max(maxPoints, sri.series.seriesElements.Count);
            }

            for (int pointIdx = 0; pointIdx < maxPoints; ++pointIdx)
            {
                double valueSumPos = 0, valueSumNeg = 0;
                foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
                {
                    if (sri.pointRendererInfos.Length <= pointIdx)
                    {
                        break;
                    }

                    ColumnRendererInfo column = (ColumnRendererInfo)sri.pointRendererInfos[pointIdx];
                    if (column.point != null && !double.IsNaN(column.point.value))
                    {
                        if (column.point.value < 0)
                        {
                            valueSumNeg += column.point.value;
                        }
                        else
                        {
                            valueSumPos += column.point.value;
                        }
                    }
                }
                yMin = Math.Min(valueSumNeg, yMin);
                yMax = Math.Max(valueSumPos, yMax);
            }
        }
        /// <summary>
        /// Calculates the position, width and height of each column of all series.
        /// </summary>
        protected override void CalcColumns()
        {
            ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;

            if (cri.seriesRendererInfos.Length == 0)
            {
                return;
            }

            double xMin       = cri.xAxisRendererInfo.MinimumScale;
            double xMajorTick = cri.xAxisRendererInfo.MajorTick;

            int maxPoints = 0;

            foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            {
                maxPoints = Math.Max(maxPoints, sri.series.seriesElements.Count);
            }

            double x = xMin + xMajorTick / 2;

            // Space used by one column.
            double columnWidth = xMajorTick * 0.75 / 2;

            XPoint[] points = new XPoint[2];
            for (int pointIdx = 0; pointIdx < maxPoints; ++pointIdx)
            {
                // Set x to first clustered column for each series.
                double yMin = 0, yMax = 0, y0 = 0, y1 = 0;
                double x0 = x - columnWidth;
                double x1 = x + columnWidth;

                foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
                {
                    if (sri.pointRendererInfos.Length <= pointIdx)
                    {
                        break;
                    }

                    ColumnRendererInfo column = (ColumnRendererInfo)sri.pointRendererInfos[pointIdx];
                    if (column.point != null && !double.IsNaN(column.point.value))
                    {
                        double y = column.point.value;
                        if (y < 0)
                        {
                            y0    = yMin + y;
                            y1    = yMin;
                            yMin += y;
                        }
                        else
                        {
                            y0    = yMax;
                            y1    = yMax + y;
                            yMax += y;
                        }

                        points[0].X = x0; // upper left
                        points[0].Y = y1;
                        points[1].X = x1; // lower right
                        points[1].Y = y0;

                        cri.plotAreaRendererInfo.matrix.TransformPoints(points);

                        column.Rect = new XRect(points[0].X,
                                                points[0].Y,
                                                points[1].X - points[0].X,
                                                points[1].Y - points[0].Y);
                    }
                }
                x++; // Next stacked column.
            }
        }