Highchart 离线导出尝试从在线 cdn 加载库并出错



我正在使用离线导出来绘制高图表,并包含以下脚本:

<script src="Scripts/highcharts/5.0.14/highcharts.js"></script>
<script src="Scripts/highcharts/5.0.14/highcharts-more.js"></script>
<script src="Scripts/highcharts/5.0.14/modules/exporting.js"></script>
<script src="Scripts/highcharts/5.0.14/modules/offline-exporting.js"></script>
<script src="Scripts/highcharts/5.0.14/modules/export-data.js"></script>

我还在我的 java 脚本中包含以下选项。

Highcharts.getSVG = function (charts, options, callback) {
var svgArr = [],
top = 0,
width = 0,
addSVG = function (svgres) {
// Grab width/height from exported chart
var svgWidth = +svgres.match(
/^<svg[^>]*widths*=s*"?(d+)"?[^>]*>/
)[1],
svgHeight = +svgres.match(
/^<svg[^>]*heights*=s*"?(d+)"?[^>]*>/
)[1],
// Offset the position of this chart in the final SVG
svg = svgres.replace('<svg', '<g transform="translate(0,' + top + ')" ');
svg = svg.replace('</svg>', '</g>');
top += svgHeight;
width = Math.max(width, svgWidth);
svgArr.push(svg);
},
exportChart = function (i) {
if (i === charts.length) {
return callback('<svg height="' + top + '" width="' + width +
'" version="1.1" xmlns="http://www.w3.org/2000/svg">' + svgArr.join('') + '</svg>');
}
charts[i].getSVGForLocalExport(options, {}, function () {
console.log("Failed to get SVG");
}, function (svg) {
addSVG(svg);
return exportChart(i + 1); // Export next only when this SVG is received
});
};
exportChart(0);
};
/**
* Create a global exportCharts method that takes an array of charts as an argument,
* and exporting options as the second argument
*/
Highcharts.exportCharts = function (charts, options) {
options = Highcharts.merge(Highcharts.getOptions().exporting, options);
// Get SVG asynchronously and then download the resulting SVG
Highcharts.getSVG(charts, options, function (svg) {
Highcharts.downloadSVGLocal(svg, options, function () {
console.log("Failed to export on client side");
});
});
};
// Set global default options for all charts
Highcharts.setOptions({
exporting: {
fallbackToExportServer: false // Ensure the export happens on the client side or not at all
}
});

现在我已经将代码部署到生产环境,当我单击下载png时,在控制台上出现错误,

加载脚本 https://code.highcharts.com/5.0.14/lib/rgbcolor.js 时出错

我不确定为什么当我在本地目录中拥有所有内容时,它试图从 highchart cdn 获取脚本。

我认为您应该将选项 libURL 设置为其他库所在的本地路径。

https://api.highcharts.com/highcharts/exporting.libURL?_ga=2.13049847.1116742286.1556551485-573722723.1548845412

最新更新