HightCharts 导出资源放在 http://export.highcharts.com/ 这个服务器上面,如果想控制导出的内容还是比较麻烦的。
有的时候希望把多张图片打包成一个PDF,或者说在PDF追加点文字。
2种方法介绍
1.webconfig 追加 httpHandlers。每次提交前走HighchartsExport.axd这里过一把。源代码下载。
<system.web> <httpHandlers> <add verb="POST" path="HighchartsExport.axd" type="Tek4.Highcharts.Exporting.HttpHandler, Tek4.Highcharts.Exporting"/> </httpHandlers> <compilation debug="true"/> </system.web>
2.在js里面post请求
<script> function download() { var chart = $(‘#container‘).highcharts() svg = chart.getSVG(); $.ajax({ async: true, url: ‘HighchartsExport.axd‘, type: ‘post‘, data: { "svg": svg }, success: function (data) { d = data; } }); } </script>
internal static void ProcessExportRequest(HttpContext context) { if (context != null && context.Request != null && context.Response != null && context.Request.HttpMethod == "POST") { HttpRequest request = context.Request; // Get HTTP POST form variables, ensuring they are not null. string filename = request.Form["filename"]; string type = request.Form["type"]; int width = 0; //这里可以得到svg 图片 string svg = request.Form["svg"]; if (filename != null && type != null && Int32.TryParse(request.Form["width"], out width) && svg != null) { // Create a new chart export object using form variables. Exporter export = new Exporter(filename, type, width, svg); // Write the exported chart to the HTTP Response object. export.WriteToHttpResponse(context.Response); // Short-circuit this ASP.NET request and end. Short-circuiting // prevents other modules from adding/interfering with the output. HttpContext.Current.ApplicationInstance.CompleteRequest(); context.Response.End(); } } }
时间: 2024-11-05 16:03:23