簡體   English   中英

從公共 highchart 導出服務器獲取 base64 圖像

[英]Get base64 image from public highchart export server

有沒有辦法從 highcharts 公共導出服務器獲取 base64 圖像(而不是 png、jpg、pdf)?

服務器: http : //export.highcharts.com/

編輯:我想要做的是在服務器端呈現圖表並將它們存儲為 base64。 我可以按照 highcharts.com/docs/export-module/render-charts-serverside 中的說明設置一個小型 Web 服務器來做到這一點,但這意味着我需要在某個地方托管它,我正在嘗試弄清楚這是不是我可以避免的事情。

由於這是我想從后端執行的操作,而無需首先呈現圖表,因此最終從公共導出服務器獲取了圖像,然后使用RestSharp進行了從后端將其轉換為base64的請求(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);
    }

我沒有在下拉列表中看到選項base64 因此,答案可能是否定的。

但是您可以獲取png,jpg或其他內容,並在線使用諸如base64之類的東西對其進行編碼。

發布很晚但是您可以從http://export.highcharts.com獲取 base64。 您需要在請求中傳遞以下配置

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

您可以使用以下示例

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM