public static void ClearFast(this ChartAreaCollection collection)
 {
     collection.SuspendUpdates();
     while (collection.Count > 0)
     {
         collection.RemoveAt(collection.Count - 1);
     }
     collection.ResumeUpdates();
 }
 public Chart()
 {
     BackColor  = Color.White;
     ChartAreas = new ChartAreaCollection();
     Series     = new SeriesCollection();
 }
        /// <summary>
        /// Fill in the list of data series names.
        /// </summary>
        /// <param name="context">Descriptor context.</param>
        /// <returns>Standart values collection.</returns>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            ArrayList values = new ArrayList();

            values.Add(Constants.NotSetValue);

            ChartAreaCollection areaCollection = null;
            string areaName = "";

            if (context != null && context.Instance != null)
            {
                if (context.Instance is Legend)
                {
                    Legend legend = (Legend)context.Instance;
                    if (legend.Common != null && legend.Common.ChartPicture != null)
                    {
                        areaCollection = legend.Common.ChartPicture.ChartAreas;
                    }
                }
                else if (context.Instance is ChartArea)
                {
                    ChartArea area = (ChartArea)context.Instance;
                    if (area.Common != null && area.Common.ChartPicture != null)
                    {
                        areaCollection = area.Common.ChartPicture.ChartAreas;
                        areaName       = area.Name;
                    }
                }
                else if (context.Instance is Title)
                {
                    Title title = (Title)context.Instance;
                    if (title.Chart != null && title.Chart.chartPicture != null)
                    {
                        areaCollection = title.Chart.chartPicture.ChartAreas;
                    }
                }

                else if (context.Instance is Annotation)
                {
                    Annotation annotation = (Annotation)context.Instance;
                    if (annotation.Chart != null && annotation.Chart.chartPicture != null)
                    {
                        areaCollection = annotation.Chart.chartPicture.ChartAreas;
                    }
                }
                else if (context.Instance is IServiceProvider)
                {
                    IServiceProvider provider = context.Instance as IServiceProvider;

                    Chart chart = provider.GetService(typeof(Chart)) as Chart;

                    if (chart != null)
                    {
                        areaCollection = chart.ChartAreas;
                    }
                }
                else if (context.Instance is Array)
                {
                    if (((Array)context.Instance).Length > 0 && ((Array)context.Instance).GetValue(0) is Legend)
                    {
                        Legend legend = (Legend)((Array)context.Instance).GetValue(0);
                        if (legend.Common != null && legend.Common.ChartPicture != null)
                        {
                            areaCollection = legend.Common.ChartPicture.ChartAreas;
                        }
                    }
                    else if (((Array)context.Instance).Length > 0 && ((Array)context.Instance).GetValue(0) is ChartArea)
                    {
                        ChartArea area = (ChartArea)((Array)context.Instance).GetValue(0);
                        if (area.Common != null && area.Common.ChartPicture != null)
                        {
                            areaCollection = area.Common.ChartPicture.ChartAreas;
                        }
                    }
                    else if (((Array)context.Instance).Length > 0 && ((Array)context.Instance).GetValue(0) is Title)
                    {
                        Title title = (Title)((Array)context.Instance).GetValue(0);
                        if (title.Chart != null && title.Chart.chartPicture != null)
                        {
                            areaCollection = title.Chart.chartPicture.ChartAreas;
                        }
                    }

                    else if (((Array)context.Instance).Length > 0 && ((Array)context.Instance).GetValue(0) is Annotation)
                    {
                        Annotation annotation = (Annotation)((Array)context.Instance).GetValue(0);
                        if (annotation.Chart != null && annotation.Chart.chartPicture != null)
                        {
                            areaCollection = annotation.Chart.chartPicture.ChartAreas;
                        }
                    }
                }
            }

            if (areaCollection != null)
            {
                foreach (ChartArea area in areaCollection)
                {
                    if (area.Name != areaName)
                    {
                        values.Add(area.Name);
                    }
                }
            }

            return(new StandardValuesCollection(values));
        }