Echart的c#生成帮助库

引用自 https://www.cnblogs.com/jack-zeng/articles/6418135.html

 

1.主要的类 

复制代码
    public class EChartOption
    {
        /// <summary>
        /// 返回JSON对象
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            string json = string.Format("({0})", Newtonsoft.Json.JsonConvert.SerializeObject(this));
            return Regex.Replace(json, "\"\\w+\":null,{0,1}", string.Empty).Replace("{,", "{").Replace(",}", "}");
        }

        public EChartTitle title { get; set; }
        public EChartTooltip tooltip { get; set; }
        public EChartLegend legend { get; set; }
        public EChartToolbox toolbox { get; set; }
        public EChartGrid grid { get; set; }
        public List<EChartxAxis> xAxis { get; set; }
        public List<EChartyAxis> yAxis { get; set; }
        public List<EChartSeries> series { get; set; }
        public EChartItemStyle itemStyle { get; set; }
        /// <summary>
        /// 雷达图
        /// </summary>
        public EChartRadar radar { get; set; }
        public bool? calculable { get; set; }
        public bool? animation { get; set; }
        public EChartName name { get; set; }
        public ArrayList color { set; get; }
    }
复制代码

2.目录结构

3.下载地址:https://files.cnblogs.com/files/jack-zeng/MySteel.Common.EChart.rar

4.基本使用

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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
  public class EchartsHelper
    {
       
                /// <summary>
        /// 柱状
        /// </summary>
        /// <returns></returns>
        public static EChartOption barInit()
        {
            EChartOption option = new EChartOption()
         {
             tooltip = new EChartTooltip()
             {
                 trigger = "item"
             },
             calculable = true,
             grid = new EChartGrid()
             {
                 left = "3%",
                 right = "4%",
                 bottom = "3%",
                 containLabel = true
             },
             xAxis = new List<EChartxAxis>()
             {
                  new EChartxAxis(){
                      type="category",
                     splitLine=new SplitLine(){
                          show=false
                       },
                        boundaryGap=true
                  }
             },
             yAxis = new List<EChartyAxis>()
             {
                  new EChartyAxis(){
                      type="value",
                      splitLine=new SplitLine(){ show=false},
                      min=null,max=null
                   }
                   
             },
             series = new List<EChartSeries>()
             {
                  new EChartSeries(){
                      type="bar",
                      barWidth="30",
                      itemStyle=new EChartItemStyle(){
                           normal=new EChartNormal(){
                                 
  label=new AxisLabel(){
       formatter="{b}\n{c}",position="top",show=true
       
}
}
}
                    }
             }
         };
            return option;
        }
 
            /// <summary>
        /// 散点图
        /// </summary>
        /// <returns></returns>
        public static EChartOption scatterInit()
        {
            EChartOption option = new EChartOption()
            {
                tooltip = new EChartTooltip()
                {
                    trigger = "item",
                    formatter = "{b} : {c} ({d}%)",
                    axisPointer = new EChartAxisPointer()
                    {
                        type = "line",
                        axis = "x",
                        lineStyle = new MySteel.Common.EChart.LineStyle()
                        {
                            color = "#000"
                        }
                    }
                },
                color = new ArrayList(),
                legend = new EChartLegend() { orient = "horizontal", x = "center", data = new ArrayList() },
                xAxis = new List<EChartxAxis>(){ new EChartxAxis(){
             splitLine=new SplitLine(){
              show=false
             },
             type="category",
             data=new ArrayList(),
 
            }},
                yAxis = new List<EChartyAxis>() { new EChartyAxis() {
                type = "value",
                nameLocation = "end",
                splitNumber=5,
                name="万吨",
                min="auto",
                max="auto",
                data=new ArrayList(),
                boundaryGap=false,
                splitLine = new SplitLine() { show = false }
                 
                } },
                animation = true,
                title = new EChartTitle() { },
                series = new List<EChartSeries>(){
        new EChartSeries(){
         type="scatter",
         symbol="none",
          markLine=new MarkLine(){
           silent=true,
           label=new EChartLabel(){normal=new EChartNormal(){show=false}, emphasis=new EChartEmphasis()
 
{show=false}},
          data=new ArrayList()
          }
        }
        }
            };
            return option;
 
        }
    /// <summary>
        /// 饼状
        /// </summary>
        /// <returns></returns>
        public static EChartOption pieInit()
        {
            EChartOption option = new EChartOption()
            {
                series = new List<EChartSeries>()
              {
                  new EChartSeries(){
                        name="",
                        type="pie",                     
                        avoidLabelOverlap=false,
                        hoverAnimation=false,
                         legendHoverLink=true,
                         label=new EChartLabel(){
                              normal=new EChartNormal(){
                                   show=true,
                                    position="center",
                                      textStyle=new EChartTextStyle(){
                                           fontFamily="Microsoft YaHei",
                                            fontSize=16,
                                              fontWeight="bold"
}
},
 emphasis=new EChartEmphasis(){
       show=true,       
        textStyle=new EChartTextStyle(){
             fontSize=14,
              fontWeight="bold"
}
}
},
 labelLine=new EChartLabelLine(){
      normal=new EChartNormal(){
           show=false
}
}, color="",
                         }
              }
            };
            return option;
        }
        /// <summary>
        /// 仪表
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static EChartOption GaugeInit(string name, string value)
        {
            EChartOption option = new EChartOption()
            {
                series = new List<EChartSeries>() {
                 new EChartSeries(){
                      name=name,
                       type="gauge",
                        radius="100%",
                       min=0,
                        max=20,
                        detail=new EChartDetail(){
                            formatter="{value}",
                             textStyle=new EChartTextStyle(){
                                 fontFamily="Microsoft YaHei",
                                 fontSize=20,
                                 fontWeight="bold"
                             },
offsetCenter=new ArrayList(){0,50}
                         },
                          pointer=new EChartPointer(){
                              width=5
                          },
                          axisLine=new AxisLine(){
                               show=true,
                          lineStyle=new  MySteel.Common.EChart.LineStyle(){
                            width=8          
                          }
                          },
                          axisTick=new AxisTick(){
                               length=12,
                                lineStyle=new MySteel.Common.EChart.LineStyle(){
                                    color="auto",width=2
                          }
                           },
                           splitLine=new SplitLine(){
                                length=20, show=true,
 
                                 lineStyle=new MySteel.Common.EChart.LineStyle(){
                                      color="auto",
                                       width=3
}
},
splitNumber=5
                     }
                }
            };
            option.series[0].data = new ArrayList() { value };
            return option;
        }
 
 
    }
posted @ 2022-12-16 16:24  wu9xia  阅读(240)  评论(0编辑  收藏  举报