更新时间:2023-02-14 09:10:59
我会改进你的第一个解决方案:
I would improve your first solution:
前三步,这里是一个简单的实现: http://jsfiddle.net/3dptu2s3/
For first three steps, here is simple implementation: http://jsfiddle.net/3dptu2s3/
和代码(注意:你不必加载Highcharts库):
And code (Note: you don't have to load Highcharts library):
一些基本选项:
some basic options:
var chartOptions = {
exporting: {
url: 'http://export.highcharts.com/'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
};
导出逻辑:
exporting logic:
var obj = {
options: JSON.stringify(chartOptions),
type: 'image/png',
async: true
},
exportUrl = chartOptions.exporting.url,
imgContainer = $("#container");
var calls = [];
for (var i = 0; i < 4; i++) {
calls.push({
type: 'post',
url: exportUrl,
data: obj,
});
}
$.when(
$.ajax(calls[0]),
$.ajax(calls[1]),
$.ajax(calls[2]),
$.ajax(calls[3])
).done(function (c1, c2, c3, c4) {
var urls = [];
$.each(arguments, function(i, chart) {
urls.push(exportUrl + chart[0]);
/*
Here you can send URLs to the backend:
$.post("url/to/backend", urls, function(data) {
console.log(data);
})
*/
});
});
事实上,您可以通过AJAX进行通信使用前端。如果您愿意,可以直接从后端使用AJAX调用。
In fact, you can communicate by AJAX without using frontend. Use AJAX calls directly from your backend if you want to.