解決Highcharts匯出時中文變亂碼
阿新 • • 發佈:2019-02-16
場景: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.
問題搞定。