当Highcharts有分页时,是否可以导出多页的Highcharts图表?

huangapple go评论102阅读模式
英文:

When highchart has pagination can we export multiple pages of highchart

问题

我有图表,有分页功能,数据来自服务器端。我正在导出一个Highchart图表的图像,使用SVG,对于单页,它可以正常工作,但问题是,当图表有分页时,是否可以导出多页。

是否可以在渲染图表之前下载图表?我有来自API的选项数据。

我正在使用这个脚本

$("body").on('click','.download-chart-btn', function() {
		html2canvas($(this).closest('.grid-stack-item-content').find('.dashboad_chart_render')[0]).then(function(canvas) {
				var imageUrl = canvas.toDataURL();
				var link = document.createElement('a');
				link.href = imageUrl;
				link.download = 'chart-image.png';
				link.click();
		});
	});

请您指导我。

英文:

I have chart which has pagination and data is coming from server side. I am export the one image of highchart using SVG it is working fine for one page but problem, is it possible to export multiple pages when chart has pagination.

Is it possible to download the chart without render chart? I have options data from API.

I am using this script

$("body").on('click','.download-chart-btn', function() {
		html2canvas($(this).closest('.grid-stack-item-content').find('.dashboad_chart_render')[0]).then(function(canvas) {
				var imageUrl = canvas.toDataURL();
				var link = document.createElement('a');
				link.href = imageUrl;
				link.download = 'chart-image.png';
				link.click();
		});
	});

Please can you guide me.

当Highcharts有分页时,是否可以导出多页的Highcharts图表?

Thanks

答案1

得分: 0

是的,可以直接创建SVG而无需渲染额外的图表。请检查getSVG图表方法以及其可选参数chartOptions

const chart = Highcharts.chart('container', {
  series: [{
    data: [...]
  }],
  ...
});

const svg = chart.getSVG({
  series: [{
    data: [...]
  }],
  ...
});

在线演示: http://jsfiddle.net/BlackLabel/qk1t6wpj/

API 参考: https://api.highcharts.com/class-reference/Highcharts.Chart#getSVG

英文:

Yes, it is possible to directly create SVG without rendering an additional chart. Please check the getSVG chart's method with its chartOptions optional parameter:

> Additional chart options for the generated SVG representation. For
> collections like xAxis, yAxis or series, the additional options is
> either merged in to the original item of the same id, or to the first
> item if a common id is not found.

const chart = Highcharts.chart('container', {
  series: [{
    data: [...]
  }],
  ...
});

const svg = chart.getSVG({
  series: [{
    data: [...]
  }],
  ...
});

Live demo: http://jsfiddle.net/BlackLabel/qk1t6wpj/

API Reference: https://api.highcharts.com/class-reference/Highcharts.Chart#getSVG

huangapple
  • 本文由 发表于 2023年7月3日 19:49:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76604461.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定