Echart的c#生成帮助库

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.基本使用

  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 @ 2017-02-20 09:13  About.Me(Name=jack)  阅读(791)  评论(1编辑  收藏  举报