Highcharts 7.1.1版如何使用amd模块离线导出PDF
Highcharts version 7.1.1 how to offline-exporting PDF with amd modules
如何使用 amd 模块 将图表 (Highcharts) 离线导出为 pdf ?
要求 jsPDF 模块抛出 "sometime" 一个 requirejs 不匹配的错误或搞乱其他要求的回调引用。
Question Highcharts 论坛:https://www.highcharts.com/forum/viewtopic.php?f=9&t=41929&sid=5178a78a6547d8fb14769a85392b276c
var chart;
require(['highcharts', 'highcharts/modules/exporting', 'highcharts/modules/offline-exporting', 'jsPDF', 'svg2pdf'], function(Highcharts, a, b, jsPDF, svg2pdf) {
window.jsPDF = jsPDF.default;
window.svg2pdf = svg2pdf;
chart = Highcharts.chart('container', {
exporting: {
libURL: 'https://code.highcharts.com/7.1.1/lib'
},
series: [{
data: [3, 4, 5, 3, 2]
}]
});
});
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.15/require.js"></script>
<script>
require.config({
packages: [{
name: 'highcharts',
main: 'highcharts',
location: 'https://code.highcharts.com/7.1.1'
}],
paths: {
'jsPDF': 'https://code.highcharts.com/7.1.1/lib/jspdf',
'svg2pdf': 'https://code.highcharts.com/7.1.1/lib/svg2pdf'
}
});
</script>
</head>
<body>
<div id="container"></div>
</body>
</html>
JsFiddle:https://jsfiddle.net/zbc149wh/2/
谢谢
您可以像这样设置离线导出
exporting: {
chartOptions: {
plotOptions: {
series: {
dataLabels: {
enabled: true
}
}
}
},
fallbackToExportServer: false
}
您的代码分叉:https://jsfiddle.net/viethien/fs03ou4k/7/
API参考:https://api.highcharts.com/highcharts/exporting.fallbackToExportServer
文档:https://www.highcharts.com/docs/export-module/client-side-export
问题来自jsPDF:
https://github.com/yWorks/jsPDF
我给所有的define语句起一个名字,所以就没有更多的匿名模块定义了。
现在可以使用了。
示例第 3 行
之前:
typeof define === 'function' && define.amd ? define(['exports'], factory) :
之后:
typeof define === 'function' && define.amd ? define('jsPDF', ['exports'], factory) :
如何使用 amd 模块 将图表 (Highcharts) 离线导出为 pdf ? 要求 jsPDF 模块抛出 "sometime" 一个 requirejs 不匹配的错误或搞乱其他要求的回调引用。
Question Highcharts 论坛:https://www.highcharts.com/forum/viewtopic.php?f=9&t=41929&sid=5178a78a6547d8fb14769a85392b276c
var chart;
require(['highcharts', 'highcharts/modules/exporting', 'highcharts/modules/offline-exporting', 'jsPDF', 'svg2pdf'], function(Highcharts, a, b, jsPDF, svg2pdf) {
window.jsPDF = jsPDF.default;
window.svg2pdf = svg2pdf;
chart = Highcharts.chart('container', {
exporting: {
libURL: 'https://code.highcharts.com/7.1.1/lib'
},
series: [{
data: [3, 4, 5, 3, 2]
}]
});
});
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.15/require.js"></script>
<script>
require.config({
packages: [{
name: 'highcharts',
main: 'highcharts',
location: 'https://code.highcharts.com/7.1.1'
}],
paths: {
'jsPDF': 'https://code.highcharts.com/7.1.1/lib/jspdf',
'svg2pdf': 'https://code.highcharts.com/7.1.1/lib/svg2pdf'
}
});
</script>
</head>
<body>
<div id="container"></div>
</body>
</html>
JsFiddle:https://jsfiddle.net/zbc149wh/2/
谢谢
您可以像这样设置离线导出
exporting: {
chartOptions: {
plotOptions: {
series: {
dataLabels: {
enabled: true
}
}
}
},
fallbackToExportServer: false
}
您的代码分叉:https://jsfiddle.net/viethien/fs03ou4k/7/
API参考:https://api.highcharts.com/highcharts/exporting.fallbackToExportServer
文档:https://www.highcharts.com/docs/export-module/client-side-export
问题来自jsPDF: https://github.com/yWorks/jsPDF
我给所有的define语句起一个名字,所以就没有更多的匿名模块定义了。 现在可以使用了。
示例第 3 行
之前:
typeof define === 'function' && define.amd ? define(['exports'], factory) :
之后:
typeof define === 'function' && define.amd ? define('jsPDF', ['exports'], factory) :