简体   繁体   中英

Get base64 image from public highchart export server

Is there any way to get a base64 image (instead of png, jpg, pdf) from highcharts public export server?

server: http://export.highcharts.com/

Edit: what I'm trying to do, is render the charts on server side and store them as base64. I'm able to do that by setting up a small web server following the instructions here highcharts.com/docs/export-module/render-charts-serverside but that means I need to host this in some place, and I'm trying to figure out if that's something I can avoid.

Since this is something I wanted to do from the backend and without the need of rendering the chart first, I ended up getting the image from the public export server and then convert it to base64 from the backend using RestSharp to do the request (C#)

public static string Render(Well well, string type)
    {
        var client = new RestClient("http://export.highcharts.com");

        StringBuilder json = new StringBuilder('the options of the chart');

        var request = new RestRequest("/", Method.POST);
        request.AddHeader("Content-Type", "multipart/form-data");
        request.AddParameter("content", "options");
        request.AddParameter("options", json);
        request.AddParameter("constr", "Chart");
        request.AddParameter("type", "image/png");
        var response = (RestResponse) client.Execute(request);
        return Convert.ToBase64String(response.RawBytes);
    }

I don't see the option base64 in the dropdown. So probably the answer is no.

But you could get the png, jpg or whatever and use something like base64 online to encode it.

Very much late to post But you can get base64 from http://export.highcharts.com . You need to pass below configuration in Request

let chartData = {
        infile: CHART_DATA,
        b64: true // Bool, set to true to get base64 back instead of binary.
        width: 600,
        constr : "Chart"
    }

You can use below example

 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);})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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