[英]HighCharts exporting filename
我使用highcharts導出模塊將圖表導出為pdf。 在我的代碼中,我創建了一個代碼段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
而警報顯示該屬性已更改。
此外,由於第一個警報顯示結果為default
(實際上不是默認值,其chart
),因此我明確表示我引用了正確的屬性,因此在錯誤的屬性中設置文件名不會導致錯誤。
任何人都可以解釋這種情況或建議更改,讓我下載動態名稱的文件。?
您可以更改文件的文件名。 這是一個如何實現這一目標的例子 。 相關代碼:
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(){
var fileName = "AAAA";//it's dynamic in reality.
this.exportChart({filename : fileName});
}
}
exportChart方法也接受選項參數..
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.