简体   繁体   English

JQXChart-如何获取图表的图像二进制(例如dataURL)

[英]JQXChart - how to get image binary (e.g. dataURL) of a chart

I'm having a JQXChart on a page: 我在页面上有一个JQXChart:

$('#chartContainer').jqxChart(settings);

What I'd like to do is the push this chart - as an image - to the server. 我想做的就是将此图表(作为图像)推送到服务器。 The component supports functionality like export to image: 该组件支持诸如导出到图像之类的功能:

https://www.jqwidgets.com/jquery-widgets-demo/demos/jqxchart/index.htm#demos/jqxchart/javascript_chart_export_jpeg.htm https://www.jqwidgets.com/jquery-widgets-demo/demos/jqxchart/index.htm#demos/jqxchart/javascript_chart_export_jpeg.htm

But I can't see any possibility to just getting the image, without actually downloading it by a web browser. 但是我看不到没有通过网络浏览器实际下载图像就获得图像的任何可能性。 I have to pass this image to the back-end service. 我必须将此图像传递给后端服务。

I saw this kind of functionality in another JS framework: 我在另一个JS框架中看到了这种功能:

http://www.jqchart.com/jquery/chart/ChartFeatures/ImageDataURL http://www.jqchart.com/jquery/chart/ChartFeatures/ImageDataURL

Is it possible in jqwidgets? jqwidgets中可能吗? Or... somehow achievable through html5... 或者...可以通过html5实现...

Thanks in advance 提前致谢

Looking at the documentation you linked it seems that the methods to export images support two arguments: fileName and exportServer . 查看链接的文档,似乎导出图像的方法支持两个参数: fileNameexportServer The documentation further states: 该文档进一步指出:

If you don't setup your own export server the default server is jqwidgets.com. 如果您未设置自己的导出服务器,则默认服务器为jqwidgets.com。

This causes the behavior of creating a download link as you described and can be seen on the example page . 这将导致您创建下载链接的行为,该行为可以在示例页面上看到。 But there is no reason you shouldn't be able to use your own server. 但是没有理由您不应该使用自己的服务器。 Since you want to push the image to your backend server anyway, just set up a corresponding route and use it in the method like: 由于您仍然想将映像推送到后端服务器,因此只需设置一条相应的路由,然后在类似的方法中使用它即可:

$('#chartContainer').jqxChart('saveAsJPEG', 'myChart.jpeg', 'http://www.yourserver.com/export')

See what arrives on the server side and go from there. 查看什么到达服务器端并从那里去。

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

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