예제 #1
0
        private void DrawSeries(Graphics g, List <UIDoughnutSeries> series)
        {
            if (series == null || series.Count == 0)
            {
                return;
            }

            for (int pieIndex = 0; pieIndex < series.Count; pieIndex++)
            {
                var pie = series[pieIndex];

                for (int azIndex = 0; azIndex < pie.Data.Count; azIndex++)
                {
                    Angle           angle = Angles[pieIndex][azIndex];
                    Color           color = ChartStyle.GetColor(azIndex);
                    UIPieSeriesData data  = pie.Data[azIndex];
                    if (data.StyleCustomMode)
                    {
                        color = data.Color;
                    }

                    if (ActiveAzIndex == azIndex)
                    {
                        g.FillFan(color, angle.Center, angle.Inner, angle.Outer + 5, angle.Start - 90, angle.Sweep);
                    }
                    else
                    {
                        g.FillFan(color, angle.Center, angle.Inner, angle.Outer, angle.Start - 90, angle.Sweep);
                    }

                    Angles[pieIndex][azIndex].TextSize = g.MeasureString(Angles[pieIndex][azIndex].Text, LegendFont);

                    if (pie.Label.Show && ActiveAzIndex == azIndex)
                    {
                        if (pie.Label.Position == UIPieSeriesLabelPosition.Center)
                        {
                            SizeF sf = g.MeasureString(pie.Data[azIndex].Name, Font);
                            g.DrawString(pie.Data[azIndex].Name, Font, color, angle.Center.X - sf.Width / 2.0f, angle.Center.Y - sf.Height / 2.0f);
                        }
                    }
                }
            }
        }
예제 #2
0
        private void DrawSeries(Graphics g, List <UIPieSeries> series)
        {
            if (series == null || series.Count == 0)
            {
                return;
            }

            if (AllIsZero)
            {
                if (series.Count > 0)
                {
                    RectangleF rect = GetSeriesRect(series[0]);
                    g.DrawEllipse(Color.Red, rect);
                }

                return;
            }

            for (int pieIndex = 0; pieIndex < series.Count; pieIndex++)
            {
                var        pie  = series[pieIndex];
                RectangleF rect = GetSeriesRect(pie);
                for (int azIndex = 0; azIndex < pie.Data.Count; azIndex++)
                {
                    Color           color = ChartStyle.GetColor(azIndex);
                    UIPieSeriesData data  = pie.Data[azIndex];
                    if (data.StyleCustomMode)
                    {
                        color = data.Color;
                    }
                    RectangleF rectx = new RectangleF(rect.X - 10, rect.Y - 10, rect.Width + 20, rect.Width + 20);
                    g.FillPie(color, (ActivePieIndex == pieIndex && ActiveAzIndex == azIndex) ? rectx : rect, Angles[pieIndex][azIndex].Start - 90, Angles[pieIndex][azIndex].Sweep);
                    Angles[pieIndex][azIndex].TextSize = g.MeasureString(Angles[pieIndex][azIndex].Text, LegendFont);

                    if (pie.Label.Show)
                    {
                        double az = Angles[pieIndex][azIndex].Start + Angles[pieIndex][azIndex].Sweep / 2;
                        double x  = Math.Abs(Math.Sin(az * Math.PI / 180));
                        double y  = Math.Abs(Math.Cos(az * Math.PI / 180));

                        string name = Option.Legend != null ? Option.Legend.Data[azIndex] + " : " : "";
                        if (pie.Data[azIndex].Value > 0)
                        {
                            string text = name + pie.Data[azIndex].Value.ToString("F0");
                            SizeF  sf   = g.MeasureString(text, SubFont);
                            PointF pf;
                            int    added = 9;
                            if (az >= 0 && az < 90)
                            {
                                pf = new PointF((float)(DrawCenter(pie).X + RadiusSize(pie) * x + added), (float)(DrawCenter(pie).Y - RadiusSize(pie) * y - sf.Height - added));
                            }
                            else if (az >= 90 && az < 180)
                            {
                                pf = new PointF((float)(DrawCenter(pie).X + RadiusSize(pie) * x + added), (float)(DrawCenter(pie).Y + RadiusSize(pie) * y + added));
                            }
                            else if (az >= 180 && az < 270)
                            {
                                pf = new PointF((float)(DrawCenter(pie).X - RadiusSize(pie) * x - added) - sf.Width, (float)(DrawCenter(pie).Y + RadiusSize(pie) * y + added));
                            }
                            else
                            {
                                pf = new PointF((float)(DrawCenter(pie).X - RadiusSize(pie) * x - added) - sf.Width, (float)(DrawCenter(pie).Y - RadiusSize(pie) * y) - sf.Height - added);
                            }

                            if (pie.Data[azIndex].Value > 0)
                            {
                                g.DrawString(text, SubFont, color, pf.X, pf.Y);
                            }
                        }
                    }
                }
            }
        }