/// <summary>
        /// Calculates the space used by the data labels.
        /// </summary>
        internal override void Format()
        {
            ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;
              foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
              {
            if (sri.dataLabelRendererInfo == null)
              continue;

            XGraphics gfx = this.rendererParms.Graphics;

            sri.dataLabelRendererInfo.Entries = new DataLabelEntryRendererInfo[sri.pointRendererInfos.Length];
            int index = 0;
            foreach (ColumnRendererInfo column in sri.pointRendererInfos)
            {
              DataLabelEntryRendererInfo dleri = new DataLabelEntryRendererInfo();
              if (sri.dataLabelRendererInfo.Type != DataLabelType.None)
              {
            if (sri.dataLabelRendererInfo.Type == DataLabelType.Value)
              dleri.Text = column.point.value.ToString(sri.dataLabelRendererInfo.Format);
            else if (sri.dataLabelRendererInfo.Type == DataLabelType.Percent)
              throw new InvalidOperationException(PSCSR.PercentNotSupportedByColumnDataLabel);

            if (dleri.Text.Length > 0)
              dleri.Size = gfx.MeasureString(dleri.Text, sri.dataLabelRendererInfo.Font);
              }

              sri.dataLabelRendererInfo.Entries[index++] = dleri;
            }
              }

              CalcPositions();
        }
        /// <summary>
        /// Calculates the data label positions specific for column charts.
        /// </summary>
        internal override void CalcPositions()
        {
            ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;
            XGraphics         gfx = this.rendererParms.Graphics;

            foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            {
                if (sri.dataLabelRendererInfo == null)
                {
                    continue;
                }

                int columnIndex = 0;
                foreach (ColumnRendererInfo bar in sri.pointRendererInfos)
                {
                    DataLabelEntryRendererInfo dleri = sri.dataLabelRendererInfo.Entries[columnIndex++];

                    dleri.Y = bar.Rect.Y + (bar.Rect.Height - dleri.Height) / 2; // Always the same...
                    switch (sri.dataLabelRendererInfo.Position)
                    {
                    case DataLabelPosition.InsideEnd:
                        // Inner border of the column.
                        dleri.X = bar.Rect.X;
                        if (bar.point.value > 0)
                        {
                            dleri.X += bar.Rect.Width - dleri.Width;
                        }
                        break;

                    case DataLabelPosition.Center:
                        // Centered inside the column.
                        dleri.X = bar.Rect.X + (bar.Rect.Width - dleri.Width) / 2;
                        break;

                    case DataLabelPosition.InsideBase:
                        // Aligned at the base of the column.
                        dleri.X = bar.Rect.X;
                        if (bar.point.value < 0)
                        {
                            dleri.X += bar.Rect.Width - dleri.Width;
                        }
                        break;

                    case DataLabelPosition.OutsideEnd:
                        // Outer border of the column.
                        dleri.X = bar.Rect.X;
                        if (bar.point.value > 0)
                        {
                            dleri.X += bar.Rect.Width;
                        }
                        else
                        {
                            dleri.X -= dleri.Width;
                        }
                        break;
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Calculates the space used by the data labels.
        /// </summary>
        internal override void Format()
        {
            ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;

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

            SeriesRendererInfo sri = cri.seriesRendererInfos[0];

            if (sri.dataLabelRendererInfo == null)
            {
                return;
            }

            double    sumValues = sri.SumOfPoints;
            XGraphics gfx       = this.rendererParms.Graphics;

            sri.dataLabelRendererInfo.Entries = new DataLabelEntryRendererInfo[sri.pointRendererInfos.Length];
            int index = 0;

            foreach (SectorRendererInfo sector in sri.pointRendererInfos)
            {
                DataLabelEntryRendererInfo dleri = new DataLabelEntryRendererInfo();
                if (sri.dataLabelRendererInfo.Type != DataLabelType.None)
                {
                    if (sri.dataLabelRendererInfo.Type == DataLabelType.Percent)
                    {
                        double percent = 100 / (sumValues / Math.Abs(sector.point.value));
                        dleri.Text = percent.ToString(sri.dataLabelRendererInfo.Format) + "%";
                    }
                    else if (sri.dataLabelRendererInfo.Type == DataLabelType.Value)
                    {
                        dleri.Text = sector.point.value.ToString(sri.dataLabelRendererInfo.Format);
                    }

                    if (dleri.Text.Length > 0)
                    {
                        dleri.Size = gfx.MeasureString(dleri.Text, sri.dataLabelRendererInfo.Font);
                    }
                }

                sri.dataLabelRendererInfo.Entries[index++] = dleri;
            }
        }
Example #4
0
        /// <summary>
        /// Calculates the data label positions specific for pie charts.
        /// </summary>
        internal override void CalcPositions()
        {
            ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;
            XGraphics         gfx = this.rendererParms.Graphics;

            if (cri.seriesRendererInfos.Length > 0)
            {
                SeriesRendererInfo sri = cri.seriesRendererInfos[0];
                if (sri != null && sri.dataLabelRendererInfo != null)
                {
                    int sectorIndex = 0;
                    foreach (SectorRendererInfo sector in sri.pointRendererInfos)
                    {
                        // Determine output rectangle
                        double midAngle    = sector.StartAngle + sector.SweepAngle / 2;
                        double radMidAngle = midAngle / 180 * Math.PI;
                        XPoint origin      = new XPoint(sector.Rect.X + sector.Rect.Width / 2,
                                                        sector.Rect.Y + sector.Rect.Height / 2);
                        double radius     = sector.Rect.Width / 2;
                        double halfradius = radius / 2;

                        DataLabelEntryRendererInfo dleri = sri.dataLabelRendererInfo.Entries[sectorIndex++];
                        switch (sri.dataLabelRendererInfo.Position)
                        {
                        case DataLabelPosition.OutsideEnd:
                            // Outer border of the circle.
                            dleri.X = origin.X + (radius * Math.Cos(radMidAngle));
                            dleri.Y = origin.Y + (radius * Math.Sin(radMidAngle));
                            if (dleri.X < origin.X)
                            {
                                dleri.X -= dleri.Width;
                            }
                            if (dleri.Y < origin.Y)
                            {
                                dleri.Y -= dleri.Height;
                            }
                            break;

                        case DataLabelPosition.InsideEnd:
                            // Inner border of the circle.
                            dleri.X = origin.X + (radius * Math.Cos(radMidAngle));
                            dleri.Y = origin.Y + (radius * Math.Sin(radMidAngle));
                            if (dleri.X > origin.X)
                            {
                                dleri.X -= dleri.Width;
                            }
                            if (dleri.Y > origin.Y)
                            {
                                dleri.Y -= dleri.Height;
                            }
                            break;

                        case DataLabelPosition.Center:
                            // Centered
                            dleri.X  = origin.X + (halfradius * Math.Cos(radMidAngle));
                            dleri.Y  = origin.Y + (halfradius * Math.Sin(radMidAngle));
                            dleri.X -= dleri.Width / 2;
                            dleri.Y -= dleri.Height / 2;
                            break;

                        case DataLabelPosition.InsideBase:
                            // Aligned at the base/center of the circle
                            dleri.X = origin.X;
                            dleri.Y = origin.Y;
                            if (dleri.X < origin.X)
                            {
                                dleri.X -= dleri.Width;
                            }
                            if (dleri.Y < origin.Y)
                            {
                                dleri.Y -= dleri.Height;
                            }
                            break;
                        }
                    }
                }
            }
        }