Exemple #1
0
        private SGCategoryAxis GetJSONCategoryAxis(Dictionary <string, object> file)
        {
            SGCategoryAxis x_axis = new SGCategoryAxis();

            x_axis.Title = Convert.ToString(jo_parsed_file["encoding"]["x"]["axis"]["title"]);

            // STUBBED
            x_axis.Origin = 0.0;
            x_axis.Width  = 500;
            x_axis.PosX   = 1;
            x_axis.PrimaryCategoryType = CategoryUnit.MONTH;
            x_axis.CategoriesTypeAxis  = TypeAxis.CONTINUOS;

            x_axis.Categories = new List <String>(); // empty list of categories
            string x_axis_labels_str = Convert.ToString(jo_parsed_file["encoding"]["x"]["scale"]["labels"]);
            object x_axis_labels     = JsonConvert.DeserializeObject(x_axis_labels_str);

            JArray labels_array = (JArray)x_axis_labels;

            // Add each categoryto our list of categories
            foreach (var category in labels_array.Children())
            {
                x_axis.Categories.Add(category.Value <string>());
            }

            x_axis.StartsAt = x_axis.Categories.First();
            x_axis.EndsAt   = x_axis.Categories.Last();
            x_axis.Stepping = Convert.ToString((Double)labels_array.ElementAt(1) - (Double)labels_array.ElementAt(0));
            return(x_axis);
        }
        public void Clean(StatisticalGraph graph)
        {
            log.Debug("Applying category axis cleaning algorithms.");

            g  = graph;
            ca = graph.CategoryAxis;

            CleanNullsCategory();

            CleanPrimaryCategories();

            CleanSecondaryCategories();
        }
        /***************************************************************************
         * Category axis properties
         **************************************************************************/
        private SGCategoryAxis GetXLCategoryAxis(Chart chart)
        {
            SGCategoryAxis sg_category_axis = new SGCategoryAxis();
            Axis           xl_category_axis = (Axis)chart.Axes(XlAxisType.xlCategory,
                                                               XlAxisGroup.xlPrimary);
            Axis xl_value_axis = (Axis)chart.Axes(XlAxisType.xlValue,
                                                  XlAxisGroup.xlPrimary);
            bool isContinuos = false;

            ///////////////////////////////////////
            //  Category axis position and width
            //////////////////////////////////////
            try
            {
                sg_category_axis.Width = xl_category_axis.Width;
                sg_category_axis.PosX  = xl_category_axis.Left;
            } catch
            {
                sg_category_axis.Width = sg.PlotArea.Geometry.Width;
                sg_category_axis.PosX  = sg.PlotArea.Geometry.PosX;
                log.Warn("There is a double axis here. Setting category axis to the"
                         + " width and  position of the plot area.");
            }

            ///////////////////////////////////////
            // Category axis title
            //////////////////////////////////////
            if (xl_category_axis.HasTitle)
            {
                sg_category_axis.Title = xl_category_axis.AxisTitle.Text;
            }
            else
            {
                sg_category_axis.Title = "none";
                log.Warn("Category axis name not found."
                         + "\n\tSetting it to: \"none\".");
            }

            ///////////////////////////////////////
            // Category axis crosses at property
            //////////////////////////////////////
            try
            {
                sg_category_axis.Origin = xl_value_axis.CrossesAt;
            } catch
            {
                //throw new Exception(IGraphConstants.kGraphErrorCrossesAt);
            }

            ///////////////////////////////////////
            // Category axis categories
            //////////////////////////////////////

            /*
             * Old Method to Get Categories
             */

            try
            {
                List <string> cats = new List <string>();
                foreach (object c in (Array)xl_category_axis.CategoryNames)
                {
                    if (c != null)
                    {
                        cats.Add(c.ToString());
                    }
                    else
                    {
                        sg_category_axis.PrimaryCategoryNulls = true;
                        cats.Add("");
                    }
                }
                sg_category_axis.Categories         = cats;
                sg_category_axis.CategoriesTypeAxis = TypeAxis.DISCRETE;
            }
            catch
            {
                //  log.Error("Couldn't get the categories values.");
                isContinuos = true;
            }


            /**
             * We are using the Series object to get the categories :)
             * http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.series.xvalues%28v=office.14%29.aspx
             */
            if (isContinuos)
            {
                IEnumerator series_enumerator = ((SeriesCollection)
                                                 chart.SeriesCollection(Type.Missing)).GetEnumerator();
                series_enumerator.MoveNext();
                Series xl_series = (Series)series_enumerator.Current;

                List <string> cats = new List <string>();
                foreach (object c in (Array)xl_series.XValues)
                {
                    if (c != null && c.ToString().Length != 0)
                    {
                        cats.Add(c.ToString());
                    }
                    else
                    {
                        sg_category_axis.PrimaryCategoryNulls = true;
                        cats.Add("");
                    }
                }
                sg_category_axis.Categories         = cats;
                sg_category_axis.CategoriesTypeAxis = TypeAxis.CONTINUOS;
            }

            return(sg_category_axis);
        }