Javascript HighCharts导出文件名

Javascript HighCharts导出文件名,javascript,highcharts,export,Javascript,Highcharts,Export,我正在使用highcharts导出模块将图表导出为pdf格式。在我的代码中,我创建了一个snippetchart对象,该对象在使用的不同gui控件上进行操作。它看起来像这样: options = { ... ... exporting:{ type: "application/pdf", filename: "default", buttons:{ exportButton:{ menuItems:

我正在使用highcharts导出模块将图表导出为pdf格式。在我的代码中,我创建了一个snippet
chart
对象,该对象在使用的不同gui控件上进行操作。它看起来像这样:

options = {
   ...
   ...
   exporting:{
      type: "application/pdf",
      filename: "default",

      buttons:{
        exportButton:{
            menuItems: null,
            onclick:function(){
                var fileName = "AAAA";//it's dynamic in reality.
                alert(options.exporting.filename);//alerts "default"
                options.exporting.filename = fileName;
                alert(options.exporting.filename);//alerts "AAAA"
                this.exportChart();
             }
         },
         printButton: {
             enabled: false
         }
      }
   }
}
现在,每当单击“导出”按钮时,下载的文件将命名为
default.pdf
,同时警报显示属性已更改

此外,由于第一个警报将结果显示为
默认值
(这不是默认值,实际上是它的
图表
),因此很明显我引用的是正确的属性,因此不会因为在错误的属性中设置文件名而出现错误


有人能解释一下情况或建议修改,让我下载动态名称的文件吗

你能试试这个吗

exportButton:{
            menuItems: null,
            onclick:function(){
                var fileName = "AAAA";//it's dynamic in reality.                                    
                this.exportChart({filename : fileName});
             }
         }

exportChart方法也接受options参数。

您可以更改文件名。下面是一个关于如何实现这一点的例子。有关守则:

exportButton: {
    menuItems: null,
    onclick: function() {
        chart.exportChart({filename: 'my-png'}, null);
    }
},
$('#buttonExport').click(function() {
    var e = document.getElementById("ExportOption");
    var ExportAs = e.options[e.selectedIndex].value;   

    if(ExportAs == 'PNG')
    {
        chart.exportChart({type: 'image/png', filename: 'my-png'}, {subtitle: {text:''}});
    }
    if(ExportAs == 'JPEG')
    {
        chart.exportChart({type: 'image/jpeg', filename: 'my-jpg'}, {subtitle: {text:''}});
    }
    if(ExportAs == 'PDF')
    {
        chart.exportChart({type: 'application/pdf', filename: 'my-pdf'}, {subtitle: {text:''}});
    }
    if(ExportAs == 'SVG')
    {
        chart.exportChart({type: 'image/svg+xml', filename: 'my-svg'}, {subtitle: {text:''}});
    }
}); 

$('#buttonPrint').click(function() {
    chart.setTitle(null, { text: ' ' });
    chart.print();
    chart.setTitle(null, { text: 'Click and drag in the plot area to zoom in' });
});
这里是另一个展示了在出口和印刷过程中可以控制的内容。有关守则:

exportButton: {
    menuItems: null,
    onclick: function() {
        chart.exportChart({filename: 'my-png'}, null);
    }
},
$('#buttonExport').click(function() {
    var e = document.getElementById("ExportOption");
    var ExportAs = e.options[e.selectedIndex].value;   

    if(ExportAs == 'PNG')
    {
        chart.exportChart({type: 'image/png', filename: 'my-png'}, {subtitle: {text:''}});
    }
    if(ExportAs == 'JPEG')
    {
        chart.exportChart({type: 'image/jpeg', filename: 'my-jpg'}, {subtitle: {text:''}});
    }
    if(ExportAs == 'PDF')
    {
        chart.exportChart({type: 'application/pdf', filename: 'my-pdf'}, {subtitle: {text:''}});
    }
    if(ExportAs == 'SVG')
    {
        chart.exportChart({type: 'image/svg+xml', filename: 'my-svg'}, {subtitle: {text:''}});
    }
}); 

$('#buttonPrint').click(function() {
    chart.setTitle(null, { text: ' ' });
    chart.print();
    chart.setTitle(null, { text: 'Click and drag in the plot area to zoom in' });
});

我想在打印图表时显示标题,但我是这样做的。setTitle({text:'SOme title'});chart.print();chart.setTitle({text:'});工作正常,但标题显示在图表线内。我无法解决它。请帮忙。