highchart导出图片

http://www.cnblogs.com/jasondan/p/3504120.html

 

项目中需求导出报表为图片存到Excel中去,或供其它页面调用。

开始存到截屏,但由于用户电脑分辨率不一样,不好处理。

后来看官方用SVG Rendering Library(其实就一Svg.dll文件)这个在后处理保存为图片然后到前台输出。

这样是可以导出了。但有时不想显示右上脚的导出按钮,直接在下一步的其它操作时并行导出。

自己写了提交SVG数据post到后台,但到后台的svg数据和官方的不一致。后来看exporting.js文件

发现传到后台之前做了好多处理:

b = b.replace(/zIndex="[^"]+"/g, "")
.replace(/isShadow="[^"]+"/g, "")
.replace(/symbolName="[^"]+"/g, "")
.replace(/jQuery[0-9]+="[^"]+"/g, "")
.replace(/url\([^#]+#/g, "url(#")
.replace(/<svg /, '<svg xmlns:xlink="http://www.w3.org/1999/xlink" ')
.replace(/ href=/g, " xlink:href=")
.replace(/\n/, " ")
.replace(/<\/svg>.*?$/, "</svg>")
.replace(/&nbsp;/g, " ")
.replace(/&shy;/g, "­")
.replace(/<IMG /g, "<image ")
.replace(/height=([^" ]+)/g, 'height="$1"')
.replace(/width=([^" ]+)/g, 'width="$1"')
.replace(/hc-svg-href="([^"]+)">/g, 'xlink:href="$1"/>')
.replace(/id=([^" >]+)/g, 'id="$1"')
.replace(/class=([^" >]+)/g, 'class="$1"')
.replace(/ transform /g, " ")
.replace(/:(path|rect)/g, "$1")
.replace(/style="([^"]+)"/g, function (a) {
return a.toLowerCase()
});
return b = b.replace(/(url\(#highcharts-[0-9]+)&quot;/g, "$1").replace(/&quot;/g, "'")
}, exportChart: function (c, a) {
var c = c || {}, d = this.options.exporting, d = this.getSVG(o({ chart: { borderRadius: 0 } }, d.chartOptions, a, {
exporting: {
sourceWidth: c.sourceWidth ||
d.sourceWidth, sourceHeight: c.sourceHeight || d.sourceHeight
}
})),
c = o(this.options.exporting, c);
f.post(c.url, {
filename: c.filename || "chart",
type: c.type,
width: c.width || 0,
scale: c.scale || 2,
svg: d
})

 

 

后来放弃了自己写方法的方式。

最后还是隐藏导出按钮,用web自动化的思想去调它自己的接口方法。

$(function () {
$("#submit").click(function () {
alert(1);
$(".highcharts-button").click();
$(".highcharts-contextmenu").children().children().eq(2).click();

// $(".highcharts-contextmenu").children().children().eq(2).click();
// alert($("#container svg"));
// $.ajax({
// url: '@Url.Content("~/Handlers/ChartExportHandler.ashx")',
// data: { svg: $("#container2").children().html(), filename: 'chart', type: 'image/jpeg', width: 1200 },
// dataType: 'text',
// async: true,
// type: "POST",
// success: function (msg) {

// if (msg == "True") {
// $('#reportTable').datagrid("reload");
// //$the.attr("src", url);
// }
// }
// });
})

转载于:https://www.cnblogs.com/8090sns/p/3680514.html

Highcharts支持将图表导出为PDF文件。要将多个导出的图表文件合并为一个PDF文件,可以使用一些第三方库或在线服务,例如PDFtk、iLovePDF等。 下面是一些基本的步骤: 1. 使用Highcharts导出图表为PDF文件,并将其保存到本地计算机上或者服务器上。 2. 在代码中使用第三方库或在线服务将每个PDF文件合并为一个文件。 3. 将合并后的PDF文件保存到本地计算机上或者服务器上。 以下是一个使用PDFtk将多个PDF文件合并为一个文件的示例代码: ```javascript // 导出第一个图表为PDF文件 Highcharts.exportCharts({ type: 'application/pdf', filename: 'chart1.pdf', sourceWidth: 600, sourceHeight: 400 }, function (pdf) { // 将第一个PDF文件保存到本地计算机或者服务器上 fs.writeFileSync('chart1.pdf', pdf); // 导出第二个图表为PDF文件 Highcharts.exportCharts({ type: 'application/pdf', filename: 'chart2.pdf', sourceWidth: 600, sourceHeight: 400 }, function (pdf) { // 将第二个PDF文件保存到本地计算机或者服务器上 fs.writeFileSync('chart2.pdf', pdf); // 使用PDFtk将两个PDF文件合并为一个文件 var cmd = 'pdftk chart1.pdf chart2.pdf cat output merged.pdf'; exec(cmd, function (error, stdout, stderr) { if (error) { console.error('Error merging PDF files:', error); } else { console.log('PDF files merged successfully.'); } }); }); }); ``` 在上面的示例代码中,我们首先导出了两个不同的图表为PDF文件,然后使用PDFtk将这两个PDF文件合并为一个文件。最终的结果文件为merged.pdf。请注意,PDFtk需要在服务器上安装,并且可以使用exec命令来执行系统命令。如果需要在客户端浏览器中合并PDF文件,可以考虑使用在线服务,例如iLovePDF等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值