简体   繁体   English

如何使用Highcharts导出多种尺寸的图表?

[英]How to export charts in multiple sizes with Highcharts?

I'm trying to create a Highchart chart that can be downloaded as a PNG in multiple resolutions. 我正在尝试创建一个Highchart图表 ,可以将其下载为多种分辨率的PNG。

I've created this JSFiddle file as a test: http://jsfiddle.net/4v133hnm/26/ 我已经创建了这个JSFiddle文件作为测试: http : //jsfiddle.net/4v133hnm/26/

Here's the relevant code, I think: 我认为这是相关的代码:

export_for_print = function() {
  var chart = $('#container').highcharts();
  chart.exportChartLocal(null, {
    chart: {
      sourceWidth: 4000,
      sourceHeight: 2000,
      scale: 6
    }
  });
};

The export works fine, but it only comes through in a single resolution. 导出工作正常,但只能通过单个分辨率进行。

If you take a look at the custom "Export for email/desktop/print" functions, I've tried changing the sourceWidth, sourceHeight, and scale attributes, but no matter what I do, the PNG downloaded from the chart is 1200x800. 如果您查看自定义的“导出为电子邮件/桌面/打印”功能,我已经尝试更改sourceWidth,sourceHeight和scale属性,但是无论如何,从图表下载的PNG都是1200x800。

I'd really appreciate any help with this issue — thanks! 非常感谢您提供有关此问题的帮助-谢谢!

The first argument is for exporting options so you should change your code to this: 第一个参数用于导出选项,因此您应该将代码更改为此:

export_for_print = function() {
  var chart = $('#container').highcharts();
  chart.exportChartLocal({
     sourceWidth: 4000,
     sourceHeight: 2000,
     scale: 6
  }, null);
};

http://api.highcharts.com/highcharts#Chart.exportChart http://api.highcharts.com/highcharts#Chart.exportChart

take a look on the documentation: 看一下文档:

You need change the scale, the scale will change your resolution. 您需要更改比例,比例将更改您的分辨率。

Here you can see one example with two different resolutions, 600x400 and 1200x800: 在这里,您可以看到一个具有两种不同分辨率(600x400和1200x800)的示例:

http://api.highcharts.com/highcharts#exporting.scale http://api.highcharts.com/highcharts#exporting.scale

 $(function () { $('#container').highcharts({ title: { text: 'Highcharts exporting scale demo' }, subtitle: { text: 'This subtitle is HTML', useHTML: true }, 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: { allowHTML: true, enabled: false } }); $('button.export').click(function () { $('#container').highcharts() .exportChart({ scale: $(this).data().scale//take a look here }); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script src="https://code.highcharts.com/highcharts.js"></script> <script src="https://code.highcharts.com/modules/exporting.js"></script> <div style="width: 600px; margin: 0 auto"> <div id="container" style="height: 400px"></div> <button class="export" data-scale="1">Scale = 1</button> <button class="export" data-scale="2">Scale = 2</button> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM