zhao
2021-07-19 8347f2fbddbd25369359dcb2da1233ac48a19fdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Xml.Linq;
 
namespace Novacode
{
    /// <summary>
    /// This element contains the 2-D bar or column series on this chart.
    /// 21.2.2.16 barChart (Bar Charts)
    /// </summary>
    public class BarChart : Chart
    {
        /// <summary>
        /// Specifies the possible directions for a bar chart.
        /// </summary>
        public BarDirection BarDirection
        {
            get
            {
                return XElementHelpers.GetValueToEnum<BarDirection>(
                    ChartXml.Element(XName.Get("barDir", DocX.c.NamespaceName)));
            }
            set
            {
                XElementHelpers.SetValueFromEnum<BarDirection>(
                    ChartXml.Element(XName.Get("barDir", DocX.c.NamespaceName)), value);
            }
        }
 
        /// <summary>
        /// Specifies the possible groupings for a bar chart.
        /// </summary>
        public BarGrouping BarGrouping
        {
            get
            {
                return XElementHelpers.GetValueToEnum<BarGrouping>(
                    ChartXml.Element(XName.Get("grouping", DocX.c.NamespaceName)));
            }
            set
            {
                XElementHelpers.SetValueFromEnum<BarGrouping>(
                    ChartXml.Element(XName.Get("grouping", DocX.c.NamespaceName)), value);
            }
        }
 
        /// <summary>
        /// Specifies that its contents contain a percentage between 0% and 500%.
        /// </summary>
        public Int32 GapWidth
        {
            get
            {
                return Convert.ToInt32(
                    ChartXml.Element(XName.Get("gapWidth", DocX.c.NamespaceName)).Attribute(XName.Get("val")).Value);
            }
            set
            {
                if ((value < 1) || (value > 500))
                    throw new ArgumentException("GapWidth lay between 0% and 500%!");
                ChartXml.Element(XName.Get("gapWidth", DocX.c.NamespaceName)).Attribute(XName.Get("val")).Value = value.ToString();
            }
        }
 
        protected override XElement CreateChartXml()
        {
            return XElement.Parse(
                @"<c:barChart xmlns:c=""http://schemas.openxmlformats.org/drawingml/2006/chart"">
                    <c:barDir val=""col""/>
                    <c:grouping val=""clustered""/>                    
                    <c:gapWidth val=""150""/>
                  </c:barChart>");
        }
    }
 
    /// <summary>
    /// Specifies the possible directions for a bar chart.
    /// 21.2.3.3 ST_BarDir (Bar Direction)
    /// </summary>
    public enum BarDirection
    {
        [XmlName("col")]
        Column,
        [XmlName("bar")]
        Bar
    }
 
    /// <summary>
    /// Specifies the possible groupings for a bar chart.
    /// 21.2.3.4 ST_BarGrouping (Bar Grouping)
    /// </summary>
    public enum BarGrouping
    {
        [XmlName("clustered")]
        Clustered,
        [XmlName("percentStacked")]
        PercentStacked,
        [XmlName("stacked")]
        Stacked,
        [XmlName("standard")]
        Standard
    }
}