码迷,mamicode.com
首页 > 其他好文 > 详细

Highcharts 二种导出方式

时间:2016-05-03 20:00:38      阅读:640      评论:0      收藏:0      [点我收藏+]

标签:

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();
    }
  }   
}

Highcharts 二种导出方式

标签:

原文地址:http://www.cnblogs.com/kfsmqoo/p/5455972.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!