56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
Highcharts.getSVG = function (charts) {
|
|
var svgArr = [],
|
|
top = 0,
|
|
width = 0;
|
|
|
|
$.each(charts, function (i, chart) {
|
|
|
|
var svg = chart.getSVG();
|
|
svg = svg.replace('<svg', '<g transform="translate(0,' + top + ')" ');
|
|
svg = svg.replace('</svg>', '</g>');
|
|
//svg = svg.replace('<svg', '<zg ct=' + chart.options.chartype);
|
|
//svg = svg.replace('</svg>', '</zg>');(这段注释的代码用来生成多个图片)
|
|
|
|
top += chart.chartHeight;
|
|
width = Math.max(width, chart.chartWidth);
|
|
|
|
svgArr.push(svg);
|
|
});
|
|
|
|
return '<svg height="' + top + '" width="' + width + '" version="1.1" xmlns="http://www.w3.org/2000/svg">' + svgArr.join('') + '</svg>';
|
|
};
|
|
Highcharts.exportCharts = function (charts, options) {
|
|
var form
|
|
svg = Highcharts.getSVG(charts);
|
|
// 合并选项
|
|
options = Highcharts.merge(Highcharts.getOptions().exporting, options);
|
|
|
|
// 新建form
|
|
form = Highcharts.createElement('form', {
|
|
method: 'post',
|
|
action: options.url
|
|
}, {
|
|
display: 'none'
|
|
}, document.body);
|
|
|
|
// 添加参数
|
|
Highcharts.each(['filename', 'type', 'width', 'svg', 'DTime'], function (name) {
|
|
Highcharts.createElement('input', {
|
|
type: 'hidden',
|
|
name: name,
|
|
value: {
|
|
filename: options.filename || 'chart',
|
|
type: options.type,
|
|
width: options.width,
|
|
svg: svg,
|
|
DTime: options.DTime //(此参数为自定义参数)
|
|
}[name]
|
|
}, null, form);
|
|
});
|
|
//console.log(svg); return;
|
|
// submit
|
|
form.submit();
|
|
//清除
|
|
form.parentNode.removeChild(form);
|
|
};
|