• Highcharts 二种导出方式


    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();
        }
      }   
    }
  • 相关阅读:
    Java阶段测试题一
    HttpClient配置及运用(一)
    字符串数组及链表的应用:例题
    Java多线程
    String普通方法测试;可变参数
    Java连接mysql数据库
    JS练习
    foreach遍历、包装类、Object类
    Java多态总结
    类的关联,不同类属性的调用
  • 原文地址:https://www.cnblogs.com/kfsmqoo/p/5455972.html
Copyright © 2020-2023  润新知