Ejemplo n.º 1
0
       private void LoadAxis()
       {
           XmlNodeList nl = _chartNode.SelectNodes("c:axId", NameSpaceManager);
           List<ExcelChartAxis> l = new List<ExcelChartAxis>();
           foreach (XmlNode node in nl)
           {
               string id = node.Attributes["val"].Value;
               var axNode = ChartXml.SelectNodes(rootPath + string.Format("/*/c:axId[@val=\"{0}\"]", id), NameSpaceManager);
               if (axNode != null && axNode.Count>1)
               {
                   foreach (XmlNode axn in axNode)
                   {
                       if (axn.ParentNode.LocalName.EndsWith("Ax"))
                       {
                           XmlNode axisNode = axNode[1].ParentNode;
                           ExcelChartAxis ax = new ExcelChartAxis(NameSpaceManager, axisNode);
                           l.Add(ax);
                       }
                   }
               }
           }
           _axis = l.ToArray();

           if(_axis.Length > 0) XAxis = _axis[0];
           if (_axis.Length > 1) YAxis = _axis[1];
       }
Ejemplo n.º 2
0
        ///// <summary>
        ///// Sets position of the axis of a chart-serie
        ///// </summary>
        ///// <param name="XAxis">Left or Right</param>
        ///// <param name="YAxis">Top or Bottom</param>
        //internal void SetAxis(eXAxisPosition XAxis, eYAxisPosition YAxis)
        //{
        //    bool xAxisExists = false, yAxisExists = false;
        //    foreach (var axis in _axis)
        //    {
        //        if (axis.AxisPosition == (eAxisPosition)XAxis)
        //        {
        //            //Found
        //            xAxisExists=true;
        //            if (axis != this.XAxis)
        //            {
        //                CheckRemoveAxis(this.XAxis);
        //                this.XAxis = axis;
        //            }
        //        }
        //        else if (axis.AxisPosition == (eAxisPosition)YAxis)
        //        {
        //            yAxisExists = true;
        //            if (axis != this.YAxis)
        //            {
        //                CheckRemoveAxis(this.YAxis);
        //                this.YAxis = axis;
        //            }
        //        }
        //    }

        //    if (!xAxisExists)
        //    {
        //        if (ExistsAxis(this.XAxis))
        //        {
        //            AddAxis((eAxisPosition)XAxis);
        //            this.XAxis = Axis[Axis.Length - 1];
        //        }
        //        else
        //        {
        //            this.XAxis.AxisPosition = (eAxisPosition)XAxis;
        //        }
        //    }
        //    if (!yAxisExists)
        //    {
        //        if (ExistsAxis(this.XAxis))
        //        {
        //            AddAxis((eAxisPosition)YAxis);
        //            this.YAxis = Axis[Axis.Length - 1];
        //        }
        //        else
        //        {
        //            this.YAxis.AxisPosition = (eAxisPosition)YAxis;
        //        }
        //    }
        //}

        /// <summary>
        /// Remove all axis that are not used any more
        /// </summary>
        /// <param name="excelChartAxis"></param>
        private void CheckRemoveAxis(ExcelChartAxis excelChartAxis)
        {
            if (ExistsAxis(excelChartAxis))
            {
                //Remove the axis
                ExcelChartAxis[] newAxis = new ExcelChartAxis[Axis.Length - 1];
                int pos = 0;
                foreach (var ax in Axis)
                {
                    if (ax != excelChartAxis)
                    {
                        newAxis[pos] = ax;
                    }
                }

                //Update all charttypes.
                foreach (ExcelChart chartType in _plotArea.ChartTypes)
                {
                    chartType._axis = newAxis;
                }
            }
        }
Ejemplo n.º 3
0
 private bool ExistsAxis(ExcelChartAxis excelChartAxis)
 {
     foreach (ExcelChart chartType in _plotArea.ChartTypes)
     {
         if (chartType != this)
         {
             if (chartType.XAxis.AxisPosition == excelChartAxis.AxisPosition ||
                chartType.YAxis.AxisPosition == excelChartAxis.AxisPosition)
             {
                 //The axis exists
                 return true;
             }
         }
     }
     return false;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Add a secondary axis
        /// </summary>
        internal void AddAxis()
        {
            XmlElement catAx = ChartXml.CreateElement(string.Format("c:{0}",AddAxType()), ExcelPackage.schemaChart);
            int axID;
            if (_axis.Length == 0)
            {
                _plotArea.TopNode.AppendChild(catAx);
                axID = 1;
            }
            else
            {
                _axis[0].TopNode.ParentNode.InsertAfter(catAx, _axis[_axis.Length-1].TopNode);
                axID = int.Parse(_axis[0].Id) < int.Parse(_axis[1].Id) ? int.Parse(_axis[1].Id) + 1 : int.Parse(_axis[0].Id) + 1;
            }


            XmlElement valAx = ChartXml.CreateElement("c:valAx", ExcelPackage.schemaChart);
            catAx.ParentNode.InsertAfter(valAx, catAx);

            if (_axis.Length == 0)
            {
                catAx.InnerXml = string.Format("<c:axId val=\"{0}\"/><c:scaling><c:orientation val=\"minMax\"/></c:scaling><c:delete val=\"0\" /><c:axPos val=\"b\"/><c:tickLblPos val=\"nextTo\"/><c:crossAx val=\"{1}\"/><c:crosses val=\"autoZero\"/><c:auto val=\"1\"/><c:lblAlgn val=\"ctr\"/><c:lblOffset val=\"100\"/>", axID, axID + 1);
                valAx.InnerXml = string.Format("<c:axId val=\"{1}\"/><c:scaling><c:orientation val=\"minMax\"/></c:scaling><c:delete val=\"0\" /><c:axPos val=\"l\"/><c:majorGridlines/><c:tickLblPos val=\"nextTo\"/><c:crossAx val=\"{0}\"/><c:crosses val=\"autoZero\"/><c:crossBetween val=\"between\"/>", axID, axID + 1);
            }
            else
            {
                catAx.InnerXml = string.Format("<c:axId val=\"{0}\"/><c:scaling><c:orientation val=\"minMax\"/></c:scaling><c:delete val=\"1\" /><c:axPos val=\"b\"/><c:tickLblPos val=\"none\"/><c:crossAx val=\"{1}\"/><c:crosses val=\"autoZero\"/>", axID, axID + 1);
                valAx.InnerXml = string.Format("<c:axId val=\"{0}\"/><c:scaling><c:orientation val=\"minMax\"/></c:scaling><c:delete val=\"0\" /><c:axPos val=\"r\"/><c:tickLblPos val=\"nextTo\"/><c:crossAx val=\"{1}\"/><c:crosses val=\"max\"/><c:crossBetween val=\"between\"/>", axID + 1, axID);
            }

            if (_axis.Length == 0)
            {
                _axis = new ExcelChartAxis[2];
            }
            else
            {
                ExcelChartAxis[] newAxis = new ExcelChartAxis[_axis.Length + 2];
                Array.Copy(_axis, newAxis, _axis.Length);
                _axis = newAxis;
            }

            _axis[_axis.Length - 2] = new ExcelChartAxis(NameSpaceManager, catAx);
            _axis[_axis.Length - 1] = new ExcelChartAxis(NameSpaceManager, valAx);
            foreach (var chart in _plotArea.ChartTypes)
            {
                chart._axis = _axis;
            }
        }