如何下载csv与codeigniter中的融合图 [英] how to download csv with fusion charts in codeigniter

查看:260
本文介绍了如何下载csv与codeigniter中的融合图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试下面的功能生成CSV下载,但我看到的是,我可以获得CSV数据只在警告

I have been trying below function to generate CSV for download, but what I am seeing is that I can get CSV data only in alert.

function ExportMyChart(type) {
    var chartObj = getChartFromId('myChartIdAmount4');
    if( chartObj.hasRendered() ){
        if(type === 'CSV'){  
            alert(chartObj.getDataAsCSV());
        }else{
            chartObj.exportChart({ exportAtClient: '1',  exportFormat: type, exportAction: 'download' }); 
        }
    }
}

chartObj.exportChart 不适用于CSV,是否有任何方式,我可以使它适用于CSV,因为它适用于PDF,JPEG?我将感谢任何帮助。感谢。

chartObj.exportChart is not working for CSV, is there any way i can make it work for CSV as it work for PDF, JPEG ?. I would appreciate any help on this. Thanks.

推荐答案

您可以通过编码CSV字符串并使用createElement锚点标签的下载方法将CSV导出为可下载文件目的。

You can export your CSV as a downloadable file by encoding the CSV string and by using download methods for createElement anchor tag object. See the code below which is a slight modification to your implementation.

请参阅我的 jsFiddle 使用FusionCharts V 3.3.1

See my jsFiddle which uses FusionCharts V 3.3.1

var exportMyChart = function (type) {
    var chartObj = FusionCharts('myChartIdAmount4');

    if (chartObj.hasRendered()) {
        if(type === 'CSV'){  
            var a = document.createElement('a');
            a.href = 'data:attachment/csv,' + encodeURIComponent(chartObj.getDataAsCSV());
            a.target = '_blank';
            a.download = 'export.csv';
            document.body.appendChild(a);
            a.click();
        }
        else{
            chartObj.exportChart({ exportAtClient: '1',  exportFormat: type, exportAction: 'download' });
        }
    }
    else{
        alert("What are you trying to export?");
    }
}

这篇关于如何下载csv与codeigniter中的融合图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆