echart asp.net 在服务器端 批量导出图表到指定文件夹

来源:互联网 发布:哪个软件容易泡妞 编辑:程序博客网 时间:2024/06/03 16:10

前台脚本

 //导出图表        function exportImage() {            if (array_charts.length < 1)            {                alert("请先查询要导出的图表");                return;            }            //array_charts为myChart对象集合  var myChart = echarts.init(document.getElementById(chartId));             $(array_charts).each(function (i, item) {                 var DataURL = item.getDataURL("png");                console.log("DataURL-----" + DataURL);                            $.ajax({                    type: "post",                    url: "/Health/AMPReport/ExportImage.ashx",                     async: true,                    data:{                        action:"saveImage",                        imgData:DataURL                    },                    cache: false,                    success: function (msg) {                    }                });            });        }


 

ExportImage.ashx页面

  public void ProcessRequest(HttpContext context)        {            context.Response.ContentType = "text/plain";            string Action = context.Request["action"];            if (context.Request.Params["action"] != null && context.Request.Params["action"].ToString() == "saveImage")            {                var ImageSend = context.Request.Params["imgData"].ToString();                int returnid = 0;                ImageSend = ImageSend.Replace(" ", "+");                try                {                    string[] url = ImageSend.Split(',');                    string u = url[1];                    // Base64解码                    byte[] b = Convert.FromBase64String(u);                    string web_path = "/files_amp/img";                    string file_path = System.Web.HttpContext.Current.Server.MapPath(web_path);                     DirectoryInfo dInfo = new DirectoryInfo(file_path);                    if (!dInfo.Exists)                    {                        dInfo.Create();                    }                    ByteStreamToFile(file_path + "/"+DateTime.Now.ToString("yyMMddHHmmss")+".png", b);                }                catch (Exception e)                {                    returnid = 1;                    string str = e.ToString();                }                 context.Response.Write(returnid);                context.Response.End();            }        }        //二进制数组Byte[]生成文件        public static bool ByteStreamToFile(string createFileFullPath, byte[] streamByte)        {            if (!File.Exists(createFileFullPath))            {                FileStream fileStream = File.Create(createFileFullPath);                fileStream.Write(streamByte, 0, streamByte.Length);                fileStream.Close();                return true;            }            return false;        }        public bool IsReusable        {            get            {                return false;            }        }

原创粉丝点击