解决Highcharts导出时中文变乱码

来源:互联网 发布:360云计算 编辑:程序博客网 时间:2024/05/21 17:27

场景:asp.net中使用Highcharts图表,使用Tek4.Highcharts.Exporting导出服务。

问题:使用Highcharts导出图片,图片上的中文全是乱码。

分析:出现乱码100%是编码的问题。

解决方案:

Tek4.Highcharts.Exporting.Exporter.cs

 internal Exporter(      string fileName,       string type,       int width,       string svg)    {      string extension;      this.ContentType = type.ToLower();      this.Name = fileName;      this.Svg = svg;      this.Width = width;      // Validate requested MIME type.      switch (ContentType)      {        case "image/jpeg":          extension = "jpg";          break;        case "image/png":          extension = "png";          break;        case "application/pdf":          extension = "pdf";          break;        case "image/svg+xml":          extension = "svg";          break;        // Unknown type specified. Throw exception.        default:          throw new ArgumentException(            string.Format("Invalid type specified: '{0}'.", type));      }      // Determine output file name.      this.FileName = string.Format(        "{0}.{1}",        string.IsNullOrEmpty(fileName) ? DefaultFileName : fileName,        extension);      // Create HTTP Content-Disposition header.YH 2012.08.07      // 用utf8编码,解决中文名称乱码问题      this.ContentDisposition =          string.Format("attachment; filename={0}", HttpUtility.UrlEncode(System.Text.UTF8Encoding.UTF8.GetBytes(this.FileName)));    }

把编码格式换成UTF8.

问题搞定。

原创粉丝点击