Highcharts - export to base64
Highcharts - export to base64
有没有一种方法可以获取一个高图,并获得它的base64表示?
换句话说,相当于先将其导出为PNG或JPG(我不在乎是哪一个),然后获得该图像的base64字符串。
以下是我解决它的方法:
-
使用google canvg它获取SVG文件的URL或SVG文件的文本,用JavaScript对其进行解析,并在Canvas元素上呈现结果。
-
使用将图表svg渲染到画布上
canvg(document.getElementById('canvas'),getSVG());
-
将画布中的内容转换为图像
var canvas = document.getElementById("canvas") ; var img = canvas.toDataURL("image/png"); //img is data:image/png;base64 img = img.replace('data:image/png;base64,', '');
-
将图像渲染到隐藏字段
$("hidden field").val(img) ;
-
要将此字符串转换为字节数组,请执行
Dim imageFile() As Byte = Convert.FromBase64String(YOUR HIDDEN FIELD .Value)
更新
获取高级图SVG
- 使用
chart.getSVG()
方法
高图表API
jsFiddle示例
- 或者简单地使用
$(your svg).html()
首先,请参阅有关导出文件的highcharts
文档。这将为您提供所需图像URL的字符串。
导出:http://www.highcharts.com/ref/#exporting
使用HTTP请求(例如使用AJAX)获取文件二进制内容(jpg/png),并将其传输到base64编码库,如以下所示:
Base64:http://www.webtoolkit.info/javascript-base64.html
祝你好运!
您可以直接从http://export.highcharts.com通过在请求中传递所需参数。
let chartData = {
infile: CHART_DATA,
b64: true // Bool, set to true to get base64 back instead of binary.
width: 600,
constr : "Chart"
}
您可以使用下面的代码段来获取base64
fetch("https://export.highcharts.com/", {
"headers": {
"content-type": "application/json",
},
"body": "{'"infile'":'"{''n '''"xAxis'''": {''n '''"categories'''": [''n '''"Jan'''",''n '''"Feb'''",''n '''"Mar'''",''n '''"Apr'''",''n '''"May'''",''n '''"Jun'''",''n '''"Jul'''",''n '''"Aug'''",''n '''"Sep'''",''n '''"Oct'''",''n '''"Nov'''",''n '''"Dec'''"''n ]''n },''n '''"series'''": [''n {''n '''"data'''": [1,3,2,4],''n '''"type'''": '''"line'''"''n },''n {''n '''"data'''": [5,3,4,2],''n '''"type'''":'''"line'''"''n }''n ]''n}''n'",'"width'":600,'"constr'":'"Chart'",'"b64'":true}",
"method": "POST",
"mode": "cors"
}).then(function(response) {
// The response is a Response instance.
return response.text();
}).then(function(data) {
console.log(data); // base64 data
}).catch(function(err) { console.log(err);})
相关文章:
- 节点Js:How to catch a“;没有这样的文件或目录“;读取线模块出错
- Html页面上的多个Base64图像和平滑加载
- 正在将base64 jpeg从input-type=file上传到服务器
- 正则表达式在字符串中找到base64
- 如何使用jquery将base64图像路径转换为真实路径
- jQuery AJAX write to XML
- grep in JQuery to C#
- how to convert html <div> to pdf
- Node.js - POST to iFrame?
- SVG xml to image
- Advantages to DOMParser vs template & innerHTML
- how to split a string with ','
- How to declare a Map containing certain properties with flow
- 无法在Cordova 4.0 ios中将jpg/jpeg图像转换为Base64
- 如何在不在本地下载的情况下将url中提供的文件(pdf/doc)转换为json/string/base64格式
- Php variable obj to js
- html image blob to base64
- Highcharts - export to base64
- Change node.js Buffer(BASE64) to jQuery
- CryptoKey ArrayBuffer to base64 and Back