Exporting several HighCharts graphs to Powerpoint slides

两盒软妹~` 提交于 2019-12-04 20:20:20

I would improve your first solution:

  • on the client side, gather options for Highcharts charts
  • send AJAX to Highcharts server with options for each of the charts. Returned will be base64 or URL to the image on the server
  • when all data will come back from your Highcharts server, use another AJAX to post URLs/images to your backend
  • in your backend (Ruby, nodeJS, whatever) gather images and generate PPT

For first three steps, here is simple implementation: http://jsfiddle.net/3dptu2s3/

And code (Note: you don't have to load Highcharts library):

  • some basic options:

    var chartOptions = {
        exporting: {
            url: 'http://export.highcharts.com/'
        },
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },
        series: [{
            data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
        }]
    };
    
  • exporting logic:

    var obj = {
            options: JSON.stringify(chartOptions),
            type: 'image/png',
            async: true
        },
        exportUrl = chartOptions.exporting.url,
        imgContainer = $("#container");
    
    var calls = [];
    
    for (var i = 0; i < 4; i++) {
        calls.push({
            type: 'post',
            url: exportUrl,
            data: obj,
        });
    }
    
    $.when(
        $.ajax(calls[0]),   
        $.ajax(calls[1]),
        $.ajax(calls[2]),
        $.ajax(calls[3])
    ).done(function (c1, c2, c3, c4) {
        var urls = [];
        $.each(arguments, function(i, chart) {
            urls.push(exportUrl + chart[0]);
            /*
                Here you can send URLs to the backend:
                $.post("url/to/backend", urls, function(data) {
                    console.log(data);
                })
            */
        });
    });
    

In fact, you can communicate by AJAX without using frontend. Use AJAX calls directly from your backend if you want to.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!